第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在頁面加載之間保留變量

在頁面加載之間保留變量

慕容3067478 2019-05-27 10:24:07
在頁面加載之間保留變量我正在嘗試捕獲我的表單的提交按鈕按下,如果表單已提交,頁面刷新,我會顯示一些隱藏的字段。我想捕獲表單是否已經(jīng)提交之前,如果它是在重新加載時提交的,我想取消隱藏隱藏的字段。我試圖使用全局變量來實(shí)現(xiàn)這一點(diǎn),但是我無法使其正常工作。這是我嘗試過的:  var clicked = false;   $(document).ready(function() {     $("input[type='submit'][value='Search']").attr("onclick", "form.act.value='detailSearch'; clicked = true;  return true;");     if (clicked == true) {       // show hidden fields     } else {       // don't show hidden fields     }   });有關(guān)此代碼有什么問題的任何建議嗎?
查看完整描述

3 回答

?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個贊

嘗試?yán)?a >$.holdReady(),history

<script src="jquery.js" type="text/javascript"></script></head><body><form method="POST">
    <input type="text" name="name" value="" />
    <input type="submit" value="Search" />
    <input type="hidden" />
    <input type="hidden" /></form><script type="text/javascript">function show() {
  return $("form input[type=hidden]")
          .replaceWith(function(i, el) {
            return "<input type=text>"
          });}$.holdReady(true);
    if (history.state !== null && history.state.clicked === true) {
       // show hidden fields
       // if `history.state.clicked === true` ,
       // replace `input type=hidden` with `input type=text`
       show();
       console.log(history);

    } else {
        // don't show hidden fields
        console.log(history);
    }$.holdReady(false);

  $(document).ready(function() {

    $("input[type=submit][value=Search]")
    .on("click", function(e) {
        e.preventDefault();
        if (history.state === null) {
          // do stuff
          history.pushState({"clicked":true});
          // replace `input type=hidden` with `input type=text`
          show();
          console.log(history);
        } else {
          // do other stuff
        };
    });

  });</script></body>


查看完整回答
反對 回復(fù) 2019-05-27
?
慕工程0101907

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個贊

使用localeStoragesessionStorage似乎是最好的選擇。

clicked變量保存在globle 范圍內(nèi)的Intead以這種方式存儲它:

if(localeStorage.getItem("clicked") === null)
    localeStorage.setItem("clicked", "FALSE"); // for the first time$(document).ready(function() {

    $("input[type='submit'][value='Search']").attr("onclick", "form.act.value='detailSearch';return true;");

    var clicked = localeStorage.getItem("clicked") == "FALSE" ? "TRUE" : "FALSE";

    localeStorage.setItem("clicked", clicked);

    if (clicked == "TRUE") {
      // show hidden fields
    } else {
      // don't show hidden fields
    }});


查看完整回答
反對 回復(fù) 2019-05-27
  • 3 回答
  • 0 關(guān)注
  • 708 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號