我有PHP數組這樣的:如何在getElementById中使用數組值?
<form name="qwerty">
<? foreach ($products as $product)?>
<input type="text" name="price1[]" id="<? $product['id']?>" value="<? $product['price1']?>" onkeyup="copy()"/>
<input type="text" name="price2[]" id="<? $product['id']?>" value="<? $product['price2']?>" />
<? end foreach?>
</form>
如何使用值id在JavaScript代碼:
<script type="text/javascript">
function copy()
{
var cc1 = document.getElementById('???????');
var cc2 = document.getElementById('???????');
cc2.value = cc1.value;
}
</script>
ID必須是**唯一的** – Andreas
爲什麼你不使用getElementsByName,因爲你必須id複雜。 –
爲什麼你的PHP變量沒有'$'? – 2013-05-18 08:42:01