добавление checkbox с onclick ...
Добрый день!
через greasemonkey в таблицу одного сайта добавляю
function insert_input()
{
var tfoot = table.getElementsByTagName("tfoot")[0];
var th = tfoot.getElementsByTagName("th")[0];
var input_ = $elem("input","",{"id":"myID","type":"checkbox","class":"check","onClick":'function(){alert("1234")}'},"",""); //
//input_.onClick = function() {alert(1234)};
th.appendChild(input_);
//document.getElementById('myID').onClick = function(){ alert(1234)};
}
function $elem(tag, content, attributes, style, parent)
{
var ret = document.createElement(tag);
if (content)
ret.innerHTML = content;
if (attributes)
for (a in attributes)
ret.setAttribute(a, attributes[a]);
if (style)
for (a in style)
ret.style[a] = style[a];
if (parent)
{
parent = (typeof(parent) == 'string') ? get(parent) : parent;
parent.appendChild(ret);
}
return ret;
}
<input type="checkbox" id="myID" class="check" onclick="function(){alert(1234)}"> но выдает синтаксическую ошибку если сделать просто
var input_ = $elem("input","",{"id":"myID","type":"checkbox","class":"check","onClick":'alert("1234")'},"","");
выводится сообщение. но мне надо анонимную функцию, т.к. код там будет намного больше чем просто alert подскажите где грабли? кстати, через input_.onClick = function() {alert(1234)}; и document.getElementById('myID').onClick = function(){ alert(1234)}; вообще в onclick не появляет то что надо |
Цитата:
<input type="checkbox" id="myID" class="check" onclick="alert(1234)" /> Цитата:
<input type="checkbox" id="myID" class="check" onclick="alert(1);alert(2);alert(3)" /> Цитата:
<input type="checkbox" id="myID" class="check" />
<script>
document.getElementById('myID').onclick = function(){ alert(1234)};
</script>
|
| Часовой пояс GMT +3, время: 01:36. |