2 備考:
<input... >
タグはタグではなく、それに応じて閉じる<input ... />
必要があります。それ以外の場合は、タグを使用する必要<button>
があります (ただし、X ブラウザーのコンプライアンス上の理由から、タグ内では使用しないでください) 。
終わりのないストーリーに入りたくない場合は、次のようにポイントを処理する方法を再考することができます:そのまま<div>
にして、その上で DOM イベントを起動します (タグで onclick イベントを使用する代わりに) . フランス語が読めるなら、ここにたくさんの例をまとめました。この方法は最初の方法よりもかなり重くなりますが、DOM で必要に応じてイベントを起動したり、コールバック関数を使用したりできるため、その後ははるかに強力になります。
原則は次のとおりです:
一方で HTML ページ
<div id="test"...>Lorem..</div>
<script src="..."/>
一方、邪魔にならない JavaScript コード
// your event handler here
function Dothisorthat(e) {
// pop up the dom content or edit it or start an ajax request or whatever you need here
return false;
}
// This is read in the third place
function attacherAction() {
// Attach the action "Dothisorthat" on the event "onclick" occuring on your div "test"
id ='test'; // your div id
if (document.getElementById(id)) {
zLink = document.getElementById(id);
zLink.onclick = function() {
Dothisorthat(this); // in your case, you can write a small function to pop up or edit the div content
}
}
}
// This is read second
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
// This is read first
addLoadEvent(attacherAction);
それが役立つことを願っています