Suppose to have an array:
array: ['hi,'by','miao']
Suppose to pass this array to one html page and I want put the second element in my html code:
<input type="button" id='{array[1]}'>....
But it doesn't work. Can anyone help me?
First of all, there's the missing quote, as @erognaut and @unenthusiasticuser have pointed out.
As far as I know, I don't think it's possible to inject JS variables into HTML like you're trying to do there. It is possible with PHP or a server-side language, though.
Or, like @jBot-42 said, you may want to change the id using JS or jQuery using a script, but not like that. For example:
<input type="button" data-id='array_elem' />
<script>
var array = ['hi','by','miao'];
// uses jQuery
$("input[data-id='array_elem']").attr("id", array[1]);
</script>
id='{array[1]}'before. I know it is possible to set the id using jQuery, is that what you are trying to do?