Javascript 如何通过获取用户输入来合并Java脚本以更改字体大小和字体颜色
我编写了单独的Javascript来更改字体颜色和字体大小。如何合并它使两者同时更改为同一字体Javascript 如何通过获取用户输入来合并Java脚本以更改字体大小和字体颜色,javascript,Javascript,我编写了单独的Javascript来更改字体颜色和字体大小。如何合并它使两者同时更改为同一字体 `enter code here` <!DOCTYPE html> <html> <body> <form> <select onchange="ChangeFont (this);" size="1"> <option value="0.1">0.1</option>
`enter code here`
<!DOCTYPE html>
<html>
<body>
<form>
<select onchange="ChangeFont (this);" size="1">
<option value="0.1">0.1</option>
<option value="0.25">0.25</option>
<option value="0.5">0.5</option>
<option value="0.75">0.75</option>
<option selected="1.0">1.0</option>
<option value="1.25">1.25</option>
<option value="1.5">1.5</option>
<option value="1.75">1.75</option>
<option value="2">2</option>
</select>
<span id="fontTest" style="font-size-adjust: 0.6">Change font-size-adjust</span>
</form>
<script type="text/javascript">
function ChangeFont (selectTag) {
// Returns the index of the selected option
var whichSelected = selectTag.selectedIndex;
// Returns the selected options values
var selectState = selectTag.options[whichSelected].text;
var fontTest = document.getElementById ("fontTest");
if ('fontSizeAdjust' in fontTest.style) {
fontTest.style.fontSizeAdjust = selectState;
} else {
alert ("Your browser doesn't support this example!");
}
}
</script>
</body>
</html>
`在此处输入代码`
0.1
0.25
0.5
0.75
1
1.25
1.5
1.75
2.
更改字体大小调整
函数ChangeFont(selectTag){
//返回所选选项的索引
var whichSelected=selectTag.selectedIndex;
//返回选定的选项值
var-selectState=selectTag.options[所选内容]。文本;
var fontTest=document.getElementById(“fontTest”);
if('fontSizeAdjust'在fontest.style中){
fontTest.style.FontSizedJust=选择状态;
}否则{
警告(“您的浏览器不支持此示例!”);
}
}
另一个是字体颜色变化:
挑选
蓝色
绿色
白色
黑色
此文本的颜色应与您在文本框中输入的颜色相同
功能更改背景(obj){
document.getElementById(“coltext”).style.color=obj.value;
}
如何合并这两个Java脚本?请帮帮我。试试这个
<!DOCTYPE html>
<html>
<body>
<form>
<select onchange="ChangeBackgroundFont(this,'font');" size="1">
<option value="0.1">0.1</option>
<option value="0.25">0.25</option>
<option value="0.5">0.5</option>
<option value="0.75">0.75</option>
<option selected="1.0">1.0</option>
<option value="1.25">1.25</option>
<option value="1.5">1.5</option>
<option value="1.75">1.75</option>
<option value="2">2</option>
</select>
<select name="color" type="text" onchange="ChangeBackgroundFont(this,'background');" >
<option value="select">Select</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="white">White</option>
<option value="black">Black</option>
</select>
<span id="fontbackgroundTest" style="font-size-adjust: 0.6">Change font-size-adjust</span>
</form>
<script type="text/javascript">
function ChangeBackgroundFont (selectTag,type) {
if(type=="font") {
// Returns the index of the selected option
var whichSelected = selectTag.selectedIndex;
// Returns the selected options values
var selectState = selectTag.options[whichSelected].text;
var fontTest = document.getElementById ("fontbackgroundTest");
if ('fontSizeAdjust' in fontTest.style) {
fontTest.style.fontSizeAdjust = selectState;
} else {
alert ("Your browser doesn't support this example!");
}
}else{
document.getElementById("fontbackgroundTest").style.color = selectTag.value;
}
}
</script>
</body>
</html>
0.1
0.25
0.5
0.75
1
1.25
1.5
1.75
2.
挑选
蓝色
绿色
白色
黑色
更改字体大小调整
函数ChangeBackgroundFont(选择标记,类型){
如果(类型==“字体”){
//返回所选选项的索引
var whichSelected=selectTag.selectedIndex;
//返回选定的选项值
var-selectState=selectTag.options[所选内容]。文本;
var fontTest=document.getElementById(“fontbackgroundTest”);
if('fontSizeAdjust'在fontest.style中){
fontTest.style.FontSizedJust=选择状态;
}否则{
警告(“您的浏览器不支持此示例!”);
}
}否则{
document.getElementById(“fontbackgroundTest”).style.color=selectTag.value;
}
}
我为你做了):请提供预期的行为,或者从用户处获得两个输入,用于更改字体和大小,两者都有单独的ID。所以,请帮助我使它成为一个javascript函数来实现这一点。感谢Mukto Mona调整我的代码:)哇..这是伟大的Jayram Prajapati。非常感谢你。保持联系……)
<!DOCTYPE html>
<html>
<body>
<form>
<select onchange="ChangeBackgroundFont(this,'font');" size="1">
<option value="0.1">0.1</option>
<option value="0.25">0.25</option>
<option value="0.5">0.5</option>
<option value="0.75">0.75</option>
<option selected="1.0">1.0</option>
<option value="1.25">1.25</option>
<option value="1.5">1.5</option>
<option value="1.75">1.75</option>
<option value="2">2</option>
</select>
<select name="color" type="text" onchange="ChangeBackgroundFont(this,'background');" >
<option value="select">Select</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="white">White</option>
<option value="black">Black</option>
</select>
<span id="fontbackgroundTest" style="font-size-adjust: 0.6">Change font-size-adjust</span>
</form>
<script type="text/javascript">
function ChangeBackgroundFont (selectTag,type) {
if(type=="font") {
// Returns the index of the selected option
var whichSelected = selectTag.selectedIndex;
// Returns the selected options values
var selectState = selectTag.options[whichSelected].text;
var fontTest = document.getElementById ("fontbackgroundTest");
if ('fontSizeAdjust' in fontTest.style) {
fontTest.style.fontSizeAdjust = selectState;
} else {
alert ("Your browser doesn't support this example!");
}
}else{
document.getElementById("fontbackgroundTest").style.color = selectTag.value;
}
}
</script>
</body>
</html>