[問題] Smarty+javascript取值
我使用smarty丟到html的array結構如下:
Array
(
[0] => Array
(
[Cell] => 10
[XX] => ABC
)
[1] => Array
(
[Cell] => 20
[XX] => DEF
)
)
html的結構如下:
<script>
function ABC(index){
document.getElementById('test').value = "{{$arr["+index+"].Cell}}";
}
</script>
<input type="text" id="test">
{{section name=sec loop=$arr}}
<a herf="#" onclick="ABC({{$smarty.section.sec.index}})">click</a>
{{/section}}
我希望點第一個click的link時,id=test的input值會變成$arr[0].Cell的值(10)
但是我這樣寫ABC()裡面的那行smarty會出錯,傳進來的index確實是0
然而document.getElementById('test').value = "{{$arr[0].Cell}}";這樣寫可以通過
要怎麼在javascript的function中的smarty語法插入javascript的變數呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.125.41.241
→
11/27 10:47, , 1F
11/27 10:47, 1F
→
11/27 10:47, , 2F
11/27 10:47, 2F
→
11/27 10:48, , 3F
11/27 10:48, 3F
→
11/27 14:12, , 4F
11/27 14:12, 4F
Web_Design 近期熱門文章
PTT數位生活區 即時熱門文章