我在javascript中创建了一个对象:
function Controller() {
this.REST_URL = "http://localhost:8081";
this.WS_URL = "ws://localhost:8080/o/sikomevents";
this.clientState = new ClientState();
this.wsIsConnected = false;
//other fields
}
// other methods...
Controller.prototype.onAgentSet = function (event) {
this.loginUserAndSubscribe($("#agent").val());
};
从html我想打电话给onAgentSet
。这是html:
<div >
<div >
<div>
<div class="agent">
<span class="s-lbl">Agent:</span>
<input id="agent" type="text"/>
<button onclick="controller.onAgentSet(event)" class="agent-btn" title="Agent wechseln"> <#-- remove class disabled if number typed in -->
<i class="material-icons">send</i>
</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var controller= new Controller();
</script>
如果在控制器对象上单击按钮但是javascript引发错误,我想调用onAgentSet:
Uncaught TypeError: controller.onAgentSet is not a function
at HTMLButtonElement.onclick ((index):410)
我希望这是一个简单的语法错误。这有什么不对?在浏览器js控制台中,我可以看到控制器对象及其方法,但似乎没有方法?!