【问题标题】:How to pass text box value as argument in jquery function on click event如何在单击事件的jquery函数中将文本框值作为参数传递
【发布时间】:2018-10-20 08:08:32
【问题描述】:

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

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

//链接在这里供点击

<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函数是follow

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 
}

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

【问题讨论】:

  • no close 我比较新鲜,一个问题很清楚你应该尊重初学者

标签: javascript php jquery textbox parameter-passing


【解决方案1】:

你可以得到它。

使用表单并获取它:

<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

【讨论】:

    【解决方案2】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多