の関数名に動的 JavaScript 変数の値を追加する方法がわかりません<a href>
。
例えば:
var x = document.getElementById('example').value // value is 6 now
<a href="javascript:function6();">+</a>
次のようにdocument.write
なります。
document.write('<a href="javascript:function"' + x + '();">Something</a>'
問題は、inner.html を使用する必要があることです。
私はそのようなコードを持っています:
<script type="text/javascript">
function count(){
var x = 1;
document.getElementById('count').value = ++x;
var z = x + 4;
}
var ex = ("<a class=\"button6\" href=\"javascript:anotherfunction\" + z + '()'>Anything else<\/a>");
function new(){
document.getElementById("add").innerHTML += ex
}
</script>
<table id="add">
<tr>
<td>
<a class="button6" href="javascript:new();count();">+</a>
</td>
</tr>
</table>
「+」リンクは、次のように、href の関数名にカウンター値を持つ別のリンクを追加する必要があります。
<a class="button6" href="javascript:anotherfunction6();">+</a>
コードの最初の「+」リンクは、href の関数名にカウンター値を持つ 2 番目のリンクを追加する必要があるため、「+」リンクを 2 回クリックすると、追加されたコードは次のようになります。
<a class="button6" href="javascript:anotherfunction6();">+</a>
<a class="button6" href="javascript:anotherfunction7();">+</a>
...
しかし、うまくいきません。