我的JS性能目標函數看起來像這樣:電話上用onclick
<script type="text/javascript">
itemOptions["_myStuff"] = {
first: "some_variable",
second: "another_variable",
getSomeValue: function(asd){
...
},
doSomething: function(){
...
}
}
some other JS stuff
</script>
然後,功能裏面,如果我想調用另一個函數,這個itemOptions["_myStuff"]
的屬性,那麼我這樣做: itemOptions["_myStuff"].doSomething();
這一切都很好,但現在我需要調用一個函數onclick
,它不工作,我想要的方式。它看起來像:
... onclick="itemOptions["_myStuff"].getSomeValue(\'' asd '\'); ...">
我試圖逃避周圍itemOptions
或_myStuff
,但沒有成功引號。任何想法如何處理這個?
P.S.代碼已經以這種格式提供給我,而我只是在其上工作,所以我不知道爲什麼這樣做。
嘗試在JavaScript_中附加您的事件以完全避免此問題。 – elclanrs
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener – ZenMaster
可能用於重複http://stackoverflow.com/questions/12879809/javascript-onclick-event-call-object, –