0

以下は、selectoptiononchange入力ボックスがselectoptionの値をエコーするときのスクリプトです。

<select id="theSelect">
 <option value="888">Foo</option>
 <option value="999">Bar</option>
</select>
<br />
<input id="someInput"/>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
  $("#theSelect").change(function() {
  $("#someInput").val($(this).val());
  }).change(); // trigger once if needed
</script>

私の質問は、アンカータグ内の値をエコーする方法です(id値を参照):

例 :<a href="index.php?id=999" id="link">Click here</a>

ありがとう。

4

2 に答える 2

3

prop()メソッドを使用hrefして、リンクの値を設定できます。

$("#theSelect").on("change", function() {
    $("#link").prop("href", "index.php?id=" + this.value);
});
于 2012-09-21T07:48:46.713 に答える
1

これを試して

</ p>

$(function() {
    $('#theSelect').on('change' , function() {
        var $anchor = $('#link')
        var currVal = $(this).find('option:selected').val();
        alert('Old href is : ' + $anchor.attr('href'));
        $anchor.attr('href' , 'index.php?id=' + currVal);
        alert('New href is : ' + $anchor.attr('href'));

    })
});​

デモをチェック

于 2012-09-21T08:04:02.980 に答える