Fiddle 脚本无法在网站上运行
Fiddle script not working on website
如果我从这里复制代码:https://jsfiddle.net/agt10exp/
它在 fiddle 上工作正常,但是当我在我的电脑上创建一个新文件并将代码粘贴到其中时,我得到相同的布局,但是它不能正常工作(添加 <html></html>
和 <script src....></script>
到我的代码:
(P.s 我是一名 Python 程序员,所以问题可能出在我的 HTML/Js 知识上)
<html>
I am a </span><select name="parent_selection" id="parent_selection">
<option value="">-- Please Select --</option>
<option value="patient">Patient</option>
<option value="doctor">Doctor or physician</option>
<option value="school">School or parent</option>
<option value="worker">Case worker</option>
</select>
<br /><span>and I need information on</span>
<select name="child_selection" id="child_selection" onchange="location = this.options[this.selectedIndex].value;">
</select>
</html>
<!------answer 1: not wokring --------------->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var jq81 = jQuery.noConflict();
jq81(document).ready(function($){
//let's create arrays
var patient = [
{display: "My initial visit", value: "patients#visit" },
{display: "My initial evaluation", value: "patients#visit" },
{display: "My appointments", value: "patients#appointments" },
{display: "Your payment policies", value: "patients#policies" }];
var doctor = [
{display: "Our approach", value: "doctors-and-physicians" },
{display: "Our services", value: "services" },
{display: "Referring patients", value: "patients#visit" }];
var school = [
{display: "Our approach", value: "schools-and-parents" },
{display: "My child's initial evaluation", value: "patients#visit" },
{display: "Setting appointments", value: "patients#appointments" },
{display: "Your payment policies", value: "patients#policies" }];
var worker = [
{display: "Our approach", value: "case-workers" },
{display: "Insurance policies", value: "clients#insurance" },
{display: "Your Payment policies", value: "patients#policies" }];
//If parent option is changed
jq81("#parent_selection").change(function() {
var parent = jq81(this).val(); //get option value from parent
switch(parent){ //using switch compare selected option and populate child
case 'patient':
list(patient);
break;
case 'doctor':
list(doctor);
break;
case 'school':
list(school);
break;
case 'worker':
list(worker);
break;
default: //default child option is blank
jq81("#child_selection").html('');
break;
}
});
//function to populate child select box
function list(array_list)
{
jq81("#child_selection").html(""); //reset child options
jq81(array_list).each(function (i) { //populate child options
jq81("#child_selection").append("<option value=\""+array_list[i].value+"\">"+array_list[i].display+"</option>");
});
}
});
</script>
看到更多遇到同样问题的人:
- Code is Working on Fiddle but not on Website
JSFiddle code not working in my own page
javascript code working in jsfiddle but not working in the browser
然而,我尝试了解决方案,但我无法弄清楚,我希望有人能帮助我
您声明自定义脚本并添加 jquery,但它们必须分开:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
+ note jquery src url
编辑:
此代码在我的 chrome
中运行良好
<html>
I am a </span><select name="parent_selection" id="parent_selection">
<option value="">-- Please Select --</option>
<option value="patient">Patient</option>
<option value="doctor">Doctor or physician</option>
<option value="school">School or parent</option>
<option value="worker">Case worker</option>
</select>
<br /><span>and I need information on</span>
<select name="child_selection" id="child_selection" onchange="location = this.options[this.selectedIndex].value;">
</select>
</html>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var jq81 = jQuery.noConflict();
jq81(document).ready(function($){
//let's create arrays
var patient = [
{display: "My initial visit", value: "patients#visit" },
{display: "My initial evaluation", value: "patients#visit" },
{display: "My appointments", value: "patients#appointments" },
{display: "Your payment policies", value: "patients#policies" }];
var doctor = [
{display: "Our approach", value: "doctors-and-physicians" },
{display: "Our services", value: "services" },
{display: "Referring patients", value: "patients#visit" }];
var school = [
{display: "Our approach", value: "schools-and-parents" },
{display: "My child's initial evaluation", value: "patients#visit" },
{display: "Setting appointments", value: "patients#appointments" },
{display: "Your payment policies", value: "patients#policies" }];
var worker = [
{display: "Our approach", value: "case-workers" },
{display: "Insurance policies", value: "clients#insurance" },
{display: "Your Payment policies", value: "patients#policies" }];
//If parent option is changed
jq81("#parent_selection").change(function() {
var parent = jq81(this).val(); //get option value from parent
switch(parent){ //using switch compare selected option and populate child
case 'patient':
list(patient);
break;
case 'doctor':
list(doctor);
break;
case 'school':
list(school);
break;
case 'worker':
list(worker);
break;
default: //default child option is blank
jq81("#child_selection").html('');
break;
}
});
//function to populate child select box
function list(array_list)
{
jq81("#child_selection").html(""); //reset child options
jq81(array_list).each(function (i) { //populate child options
jq81("#child_selection").append("<option value=\""+array_list[i].value+"\">"+array_list[i].display+"</option>");
});
}
});
</script>
如果我从这里复制代码:https://jsfiddle.net/agt10exp/
它在 fiddle 上工作正常,但是当我在我的电脑上创建一个新文件并将代码粘贴到其中时,我得到相同的布局,但是它不能正常工作(添加 <html></html>
和 <script src....></script>
到我的代码:
(P.s 我是一名 Python 程序员,所以问题可能出在我的 HTML/Js 知识上)
<html>
I am a </span><select name="parent_selection" id="parent_selection">
<option value="">-- Please Select --</option>
<option value="patient">Patient</option>
<option value="doctor">Doctor or physician</option>
<option value="school">School or parent</option>
<option value="worker">Case worker</option>
</select>
<br /><span>and I need information on</span>
<select name="child_selection" id="child_selection" onchange="location = this.options[this.selectedIndex].value;">
</select>
</html>
<!------answer 1: not wokring --------------->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var jq81 = jQuery.noConflict();
jq81(document).ready(function($){
//let's create arrays
var patient = [
{display: "My initial visit", value: "patients#visit" },
{display: "My initial evaluation", value: "patients#visit" },
{display: "My appointments", value: "patients#appointments" },
{display: "Your payment policies", value: "patients#policies" }];
var doctor = [
{display: "Our approach", value: "doctors-and-physicians" },
{display: "Our services", value: "services" },
{display: "Referring patients", value: "patients#visit" }];
var school = [
{display: "Our approach", value: "schools-and-parents" },
{display: "My child's initial evaluation", value: "patients#visit" },
{display: "Setting appointments", value: "patients#appointments" },
{display: "Your payment policies", value: "patients#policies" }];
var worker = [
{display: "Our approach", value: "case-workers" },
{display: "Insurance policies", value: "clients#insurance" },
{display: "Your Payment policies", value: "patients#policies" }];
//If parent option is changed
jq81("#parent_selection").change(function() {
var parent = jq81(this).val(); //get option value from parent
switch(parent){ //using switch compare selected option and populate child
case 'patient':
list(patient);
break;
case 'doctor':
list(doctor);
break;
case 'school':
list(school);
break;
case 'worker':
list(worker);
break;
default: //default child option is blank
jq81("#child_selection").html('');
break;
}
});
//function to populate child select box
function list(array_list)
{
jq81("#child_selection").html(""); //reset child options
jq81(array_list).each(function (i) { //populate child options
jq81("#child_selection").append("<option value=\""+array_list[i].value+"\">"+array_list[i].display+"</option>");
});
}
});
</script>
看到更多遇到同样问题的人:
- Code is Working on Fiddle but not on Website
JSFiddle code not working in my own page javascript code working in jsfiddle but not working in the browser
然而,我尝试了解决方案,但我无法弄清楚,我希望有人能帮助我
您声明自定义脚本并添加 jquery,但它们必须分开:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
+ note jquery src url
编辑: 此代码在我的 chrome
中运行良好<html>
I am a </span><select name="parent_selection" id="parent_selection">
<option value="">-- Please Select --</option>
<option value="patient">Patient</option>
<option value="doctor">Doctor or physician</option>
<option value="school">School or parent</option>
<option value="worker">Case worker</option>
</select>
<br /><span>and I need information on</span>
<select name="child_selection" id="child_selection" onchange="location = this.options[this.selectedIndex].value;">
</select>
</html>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
var jq81 = jQuery.noConflict();
jq81(document).ready(function($){
//let's create arrays
var patient = [
{display: "My initial visit", value: "patients#visit" },
{display: "My initial evaluation", value: "patients#visit" },
{display: "My appointments", value: "patients#appointments" },
{display: "Your payment policies", value: "patients#policies" }];
var doctor = [
{display: "Our approach", value: "doctors-and-physicians" },
{display: "Our services", value: "services" },
{display: "Referring patients", value: "patients#visit" }];
var school = [
{display: "Our approach", value: "schools-and-parents" },
{display: "My child's initial evaluation", value: "patients#visit" },
{display: "Setting appointments", value: "patients#appointments" },
{display: "Your payment policies", value: "patients#policies" }];
var worker = [
{display: "Our approach", value: "case-workers" },
{display: "Insurance policies", value: "clients#insurance" },
{display: "Your Payment policies", value: "patients#policies" }];
//If parent option is changed
jq81("#parent_selection").change(function() {
var parent = jq81(this).val(); //get option value from parent
switch(parent){ //using switch compare selected option and populate child
case 'patient':
list(patient);
break;
case 'doctor':
list(doctor);
break;
case 'school':
list(school);
break;
case 'worker':
list(worker);
break;
default: //default child option is blank
jq81("#child_selection").html('');
break;
}
});
//function to populate child select box
function list(array_list)
{
jq81("#child_selection").html(""); //reset child options
jq81(array_list).each(function (i) { //populate child options
jq81("#child_selection").append("<option value=\""+array_list[i].value+"\">"+array_list[i].display+"</option>");
});
}
});
</script>