我收到以下错误
未捕获的TypeError:无法读取null的属性'appendChild'
myRequest.onreadystatechange @ script.js:20
用我的以下代码
// index.html
<html>
<head>
<title>Simple Page</title>
</head>
<body>
<div id="mainContent">
<h1>This is an AJAX Example</h1>
</div>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的JavaScript文件
// script.js
// 1. Create the request
var myRequest;
// feature check!
if(window.XMLHttpRequest) { // Firefox, Safari
myRequest = new XMLHttpRequest();
} else if (window.ActiveXObject){ // IE
myRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
// 2. Create an event handler for our request to call back
myRequest.onreadystatechange = function() {
console.log("We were called!");
console.log(myRequest.readyState); …Run Code Online (Sandbox Code Playgroud) 我有两(2)个问题:首先,如何interface使用Python 创建FlyBehavior ?其次,如何implement使用Python在FlyWithWings类中的FlyBehavior接口(请参见下文)?我正在从头开始学习设计模式,并且想使用Python重写以下Java类
public abstract class Duck {
// Reference variables for the
// behavior interface types
FlyBehavior flyBehavior;
QuackBehavior quackBehavior;
public Duck() {
}
// Delegate to the behavior class
public void performFly(){
flyBehavior.fly();
}
// Delegate to the behavior class
public void performQuack(){
quackBehavior.quack();
}
}
Run Code Online (Sandbox Code Playgroud)
这是所有飞行行为类实现的接口
public interface FlyBehavior {
public void fly();
}
Run Code Online (Sandbox Code Playgroud)
这是做鸭子飞行行为的实现
public class FlyWithWings implements FlyBehavior {
public void fly(){
System.out.println("I'm flying");
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我使用Python所拥有的。以下是我的Python抽象Duck类
import abc
class Duck: …Run Code Online (Sandbox Code Playgroud) 当用户使用jQuery和regex输入除数字以外的任何内容时,我试图显示错误消息.我该怎么做呢?
if( $(this).val().match(/^[0-9]$/) ){
alert("Wrong input. Only numbers allowed");
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用,!但它没有工作,我没有收到任何错误消息
if( $(this).val().match(/![0-9]/) ){
alert("Wrong input. Only numbers allowed");
}
Run Code Online (Sandbox Code Playgroud)