如何在单击事件的 jquery 函数中将文本框值作为参数传递

How to pass text box value as argument in jquery function on click event

我想在点击时获取文本框的值作为参数

<input type="text" id="remark_mention" />

// link点击这里

<a class="remark  "href="javascript:void(0);"style="text-decoration:none;color:#d90000;" id="st_mention<?php echo strip_tags($row["pid"]); ?>" onClick="mention_or_remmove_remarks('<?php echo strip_tags($row["pid"]); ?>','st_mention');"> Mention</a>

我的jquery功能是跟随

function mention_or_remmove_remarks(mention_id, action){
    var dataString = "mention_id=" + mention_id + "&action=mention_or_remmove_remarks";//ajax code here for post mention_update.php 
}

如何在 link Onclick 事件中获取文本框的值

你可以得到它。

使用表单并获取:

<form>
 <input type="text" id="remark_mention" name="remark_mention_ID"/>
<input type="button" onclick="foo(this.form.remark_mention_ID.value)"/>
</form>

或:

<input type="text" id="remark_mention" />

并在您的 js 文件中:

var value = $('#remark_mention').val(); // value variable has your latest value

Html

<input type="text" id="remark_mention" />
<a class="remark "href="javascript:void(0);"> Mention</a>

Js

$('.remark').on('click', function(){
    var text_val = $('#remark_mention').val();
    console.log(text_val);
});

jsfiddle demo