简体   繁体   English

当用户单击该超链接时,如何设置从超链接到jQuery对话框弹出窗口上的隐藏字段的超链接文本的值?

[英]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.

相关问题 页面上所有超链接的jQuery模式对话框 - Jquery modal dialog on all hyperlink clicks in a page 是否可以超链接嵌入式视频框,以便在用户点击视频时显示超链接? - Is it possible to hyperlink an embedded video box so when a user clicks on the video a hyperlink is brought up? 单击超链接文本后,如何将锚标记中存在的值设置为隐藏字段(即锚标记中存在的值)? - How to set a value present in anchor tag to a hidden field upon clicking on the hyperlink text(i.e. value present in anchor tag)? 将javascript弹出功能链接到超链接标记 - Linking a javascript pop-up function to a hyperlink-tag JQuery和PhoneGap-监听超链接的点击 - JQuery and PhoneGap - Listening for hyperlink clicks Jquery对话框 - 单击超链接时打开 - Jquery Dialog Box - to open when clicked a hyperlink 检测文本中的超链接 - jQuery - Detect a hyperlink in a text - jQuery 如何从带有 Python 的按钮中抓取隐藏的超链接? - How to scrape a hidden hyperlink from a button with Python? 如何通过单击超链接打开引导程序模版中的文本框来设置其值? - How to set value to a text-box present on bootstrap modal after it opened up by clicking on a hyperlink? 使用 jQuery 更改超链接文本的值 - Change value of hyperlink text using jQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM