[英]How to set a value of hyperlink text from a hyperlink to a hidden field on a jQuery dialog pop-up when user clicks on that hyperlink?
I'm using PHP, Smarty, jQuery(jquery-1.7.1.min.js), Javascript, AJAX, etc. in my website. 我在网站上使用PHP,Smarty,jQuery(jquery-1.7.1.min.js),Javascript,AJAX等。 Now there are multiple hyperlinks containing different question ids are present on my webpage.
现在,我的网页上存在多个包含不同问题ID的超链接。 For instance I'm showing the HTML code for one hyperlink as follows:
例如,我正在显示一个超链接的HTML代码,如下所示:
<a class="que_issue" href="#">QUE38552</a>
<!--There are many other hyperlinks are present on the same page with different question ids.-->
Now I've HTML code for a dialog pop-up on the same web page which is set to style="display:none;"
现在,我已经在同一网页上将对话框弹出式窗口的HTML代码设置为
style="display:none;"
in a div
when page loads. 页面加载时在
div
。 This is done to hide the dialog box when the page loads. 这样做是为了在页面加载时隐藏对话框。 When user clicks on any of the hyperlinks the dialog pop-up appears.
当用户单击任何超链接时,将显示对话框弹出窗口。 The script for this functionality is working fine.
此功能的脚本运行正常。 The HTML of the dialog pop-up is as follows:
对话框弹出的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>
Now my issue is I'm not able to set the value of question id clicked to a hidden field(having id="question_id" ) on a dialog pop-up. 现在我的问题是我无法在对话框弹出窗口中将单击的问题ID的值设置为隐藏字段(具有id =“ question_id” )。 I tried following script for doing it but it didn't worked.
我尝试按照以下脚本进行操作,但没有成功。 Following is the Javascript code I tried:
以下是我尝试过的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;
});
Following is the jQuery code I tried: 以下是我尝试过的jQuery代码:
$('.que_issue').click(function(e){
e.preventDefault();
$('#question_id').val($.trim($(this).text()).substring(3));
});
Both of the above code didn't wor for me. 上面的两个代码都不适合我。 But when I removed the line
style="display:none;"
但是当我删除line
style="display:none;"
from the dialog pop-up's div
the dialog pop-up displays at the bottom of the page and when I click on specific question id, the question id also gets set to the hidden field at the form appearing at the bottom of the page. 从对话框弹出窗口的
div
,对话框弹出窗口显示在页面底部,当我单击特定的问题ID时,问题ID也会被设置为页面底部显示的表单的隐藏字段。 But still the hidden field on a dialog pop-up the value didn't set. 但是,对话框上的隐藏字段仍未设置该值。 I'm totally clue-less after trying every possible thing and googling.
在尝试了所有可能的事情并进行谷歌搜索之后,我完全一无所知。 Can anyone please help me in this regard please?
有人可以在这方面帮助我吗? Thank you so much for spending some of your valuable time and understanding my issue.
非常感谢您花费宝贵的时间并理解我的问题。 Thanks once again.
再次感谢。 If you want some more information regarding my issue I can provide you the same.
如果您需要有关我的问题的更多信息,我可以为您提供同样的信息。
设置ID之前,请将其传递给var。
If you want to add the value attribute, then use: 如果要添加value属性,请使用:
$('.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());
});
Check the console to make sure the value is being printed twice. 检查控制台,确保该值被打印两次。 Fiddle
小提琴
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.