2014-03-06 39 views
0

我在我的網站上使用PHP,Smarty,jQuery(jquery-1.7.1.min.js),Javascript,AJAX等。現在我的網頁上有多個包含不同問題ID的超鏈接。比如我展示了一個超鏈接的HTML代碼如下:當用戶點擊該超鏈接時,如何設置從超鏈接超鏈接文本的值到jQuery對話框上的隱藏字段彈出?

<a class="que_issue" href="#">QUE38552</a> 
<!--There are many other hyperlinks are present on the same page with different question ids.--> 

現在我已經HTML代碼在同一網頁上一個對話框彈出被設置爲style="display:none;"div頁面加載時。這是爲了在頁面加載時隱藏對話框。當用戶點擊任何超鏈接時,彈出對話框。這個功能的腳本工作正常。對話框彈出的HTML如下:

<div id="searchPopContent" class="c-popup" style="display:none;"> 
    <div id="pop-up"> 
    <div class="error_msg" id="report_error" style="text-align:center; margin-top:5px;"> 

    </div> 
    <div class="clear"></div> 
    <form name="question_issue_form" id="question_issue_form" class="login_box" method="post" action="question_issue.php"> 
     <input type="hidden" name="form_submitted" id="form_submitted" value="yes"/> 
     <input type="hidden" name="post_url" id="post_url" value="question_issue.php"/> 
     <input type="hidden" name="op" id="op" value="question_issue"/> 
     <input type="hidden" name="question_id" id="question_id"/> 

     <table class="trnsction_details" width="100%" cellpadding="5"> 
     <tbody>  
      <tr> 
      <td></td> 
      <td> 
       <input type="checkbox" name = "que_issue[]" value = "Question is wrong" id ="chkQueWrong">Question is wrong</input> 
      </td> 
      </tr> 
      <tr> 
      <td></td> 
      <td><input type="checkbox" name = "que_issue[]" value = "Answers are wrong" id ="chkAnsWrong">Answers are wrong</input></td> 
      </tr> 
      <tr> 
      <td></td> 
      <td><input type="checkbox" name = "que_issue[]" value = "Question direction is incorrect" id ="chkDirIncorrect">Question direction is incorrecct</input></td>    
      </tr> 
      <tr> 
      <td></td> 
      <td><input type="checkbox" name = "que_issue[]" value = "Other" id ="chkOther">Other</input></td>   
      </tr> 
      <tr> 
      <td></td> 
      <td class="set_message" style="display:none;"><textarea name="que_issue_comment" id = "que_issue_comment" rows="4" cols="25" maxlength="100"></textarea></td>  
      </tr> 
      <tr> 
      <td></td> 
      <td><input type="submit" name="submit" value="Submit" class="report_question_issue" class="buttonin"/></td> 
      </tr> 
     </tbody> 
     </table> 
    </form> 
    </div> 
</div> 

現在我的問題是我不能夠設置問題id的值點擊到一個隱藏字段(具有ID =「question_id」)彈出一個對話框。我嘗試了下面的腳本,但它沒有奏效。 以下是Javascript代碼我想:

$(document).on("click","a[class='que_issue']", function (e) { 
var x = this.innerHTML; 
    var str = x.substring(3); 
document.getElementById("question_id").value = str; 
}); 

以下是jQuery代碼我想:

$('.que_issue').click(function(e){ 
e.preventDefault(); 
$('#question_id').val($.trim($(this).text()).substring(3)); 
}); 

兩個上面的代碼沒有對活像我。但是,當我從對話框彈出框div中刪除線style="display:none;"時,對話框彈出窗口顯示在頁面底部,當我單擊特定問題ID時,問題ID也被設置爲出現在窗體中的隱藏字段頁面的底部。但仍然彈出對話框的隱藏字段值沒有設置。嘗試所有可能的事情並使用Google搜索後,我完全沒有辦法。任何人都可以請幫我在這方面嗎?非常感謝你花了一些寶貴的時間和理解我的問題。再次感謝。如果你想了解更多有關我的問題的信息,我可以爲你提供相同的信息。

+1

http://jsfiddle.net/anandnat/vcH6X/1/ –

+0

我正確地說當隱藏的輸入是更新時,它在包含div時從display:none設置爲可見顯示? – ravb79

+0

因爲我猜你試圖操縱隱藏的輸入,而它在一個顯示元素:沒有設置。如果您希望保持顯示:無,請將文本存儲在範圍內的一個變量中,然後在顯示後將其設置爲:none已被刪除。 – ravb79

回答

0

在設置它之前,將ID傳遞給var。

+0

不,它不工作。該值仍未設置爲隱藏字段。這是一個隱藏的領域,而不是一個textarea。那麼我應該如何使用文字而不是價值? – PHPLover

+1

你是對的。在我發佈我愚蠢的智慧答案的那一刻,我突然被迫時間緊張,而且我使用手機這樣做也沒有幫助。 – ravb79

0

如果你想添加值的屬性,然後使用:

$('.que_issue').click(function(e){ 
    e.preventDefault(); 
    $('#question_id').prop("value", $.trim($(this).text()).substring(3)); 
    console.log($.trim($(this).text()).substring(3)); 
    console.log($('#question_id').val()); 
}); 

檢查控制檯以確保正在打印兩倍。 Fiddle