1

より明確にするために更新されました:

値「1201026404」を含む現在のフィールド(毎回変更されます):

<input id="ticket_fields_20323656" name="ticket[fields][20323656]" size="30" style="width:125px;" type="text" value="1201026404" tabindex="11">

コピーした値「1201026404」(毎回変更されます)をページの読み込み時に移動するLI:

<ul class="multi_value_field" style="width: 99.5%;">
<li class="choice" choice_id="1201026404">1201026404<a class="close">×</a><input type="hidden" name="ticket[set_tags][]" value="1201026404" style="display: none;"></li>
</ul>

私がすでに作成したが、助けが必要なJavascript:

<script type="text/javascript">
copy = function()
{
    var n1 = document.getElementById("ticket_fields_20323656");
    var n2 = ‘what goes here??’
    n2.value = n1.value;
}
</script>
4

2 に答える 2

0

li 要素で ID を使用する必要があります。

 <li id="choice_20323656">

次に、次のようにコピーできます

<script type="text/javascript">
copy = function()
{
    var n1 = document.getElementById("ticket_fields_20323656");
    var n2 = document.getElementById("choice_20323656");
    n2.innerHTML = n1.value;
}
</script>

編集:

jQuery 1.6以降を使用できる場合、これは機能します:

$("#ticket_fields_20323656").keyup(function(e) {
    $(".choice")
        .attr("choice_id",e.currentTarget.value)
        .html(e.currentTarget.value
              + "<a class=\"close\">×</a><input" 
              + " type=\"hidden\" name=\"ticket" 
              + "[set_tags][]\" value=\"" 
              + e.currentTarget.value 
              + "\" style=\"display: none;\">");
});​

ここにデモがあります: http://jsfiddle.net/JKirchartz/V2L25/choiceただし、クラスに複数のものがある場合、それらの値は次のように同じように変化することを知っておく必要があります: http://jsfiddle.net/ JKirchartz/V2L25/4/

于 2012-11-13T03:48:34.370 に答える
0

これはFirefoxで機能しますか:

<script type="text/javascript">
copy = function()
{
    var n1 = document.getElementById("ticket_fields_20323656");
    var n2 = document.querySelectorAll("ul.multi_value_field li:first");
    n2.innerHTML = n1.value;
}
</script>

これは、IE6、7、8には存在しないquerySelectorAllを使用します-そうでない場合は、持っているかどうかわからない要素のIDを使用する必要があります

于 2012-11-13T03:49:38.700 に答える