[英]php array value from data tag to jQuery
我試圖從數據標簽獲取數組值到jQuery,但無法正常工作。 這是我的代碼:
//$b is taking names from text-area separated by comma.
$a = array_map('trim', explode(",", $b));
return <input type="text" id="pct"><button id="pcthit">submit</button><p id="pct_avail"></p></span>
<input type="hidden" id="storageElement" data-storeIt="'.$a.'">';
$("#pcthit").click(function(){
var pstcde = $("#pct").val();
var retrieved_string = [];
var retrieved_string = $("#storageElement").data('storeit');
if((pstcde != '') && (jQuery.inArray(pstcde, retrieved_string) >= 0 )){
$("#pct_avail").html('hello');
}
});
您需要使用json_encode()
對數組進行編碼。
return '<input type="text" id="pct"><button id="pcthit">submit</button>
<p id="pct_avail"></p></span>
<input type="hidden" id="storageElement" data-storeIt=\''.json_encode($a).'\'>';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.