1.用jQuery编程实现获取选中复选框值的函数abc。

 <body>
<input type="checkbox" name="aa" value="0" />0
<input type="checkbox" name=" aa " value="1" />1
<input type="checkbox" name=" aa " value="2" />2
<input type="checkbox" name=" aa " value="3" />3
<input type="button" onclick="abc ( )" value="提 交" />
<div id="allselect"></div>
</body>

答案:

 function abc(){
$("input:checked").each(function(){
alert($(this).val())
})
}

2.实现foo函数弹出对话框提示当前选中的是第几个单选框。

 <html>
<body>
<form name="form1" onsubmit="return foo();">
<input type="radio" name="radioGroup"/>
<input type="radio" name="radioGroup"/>
<input type="radio" name="radioGroup"/>
<input type="radio" name="radioGroup"/>
<input type="radio" name="radioGroup"/>
<input type="radio" name="radioGroup"/>
<input type="submit"/>
</form>
</body>
</html>

答案:

<script>
function foo(){
var a=document.getElementsByName("radioGroup");
for(var i=0;i<a.length;i++){
if(a[i].checked){
alert(i+1);
}
}
}
</script>

3.实现LoadImg函数改变下拉列表框显示图片,并显示在文本框中。

 <html>
<head>
<title>图像切换</title>
</head>
<body>
<form name="form1" >
<p><input type="text" name="T1" size="20">
<select size="1" name="D1" onchange="LoadImg(this.form)">
<option selected value="images\img01.jpg">图片一</option>
<option value="images\img02.jpg">图片二</option>
<option value="images\img03.jpg">图片三</option>
</select></p>
<img src="data:images\Img01.jpg" name="img1" width=250 height=200>
</form>
</body>
</html>

答案:

 <script>
function LoadImg(f){
var a=document.getElementsByName("T1")[0];
var b=document.getElementsByName("D1")[0];
var c=document.getElementsByName("img1")[0];
a.value=b.options[b.selectedIndex].text;
c.src=b.options[b.selectedIndex].value;
}
</script>

4.要求用jQuery完成:  点击id为btn的按钮

a.判断id为username的输入是否为空,如果为空,则弹出“用户名不能为空”的提示。

b.判断id为password的输入字符串个数是否小于6位,如果小于6位,则弹出“你输入的密码长度不可以少于6位”的提示

 <body>
用户名:<input type="text" id="username"/><br/>
密 码:<input type="password" id="password"/><br/>
       确认密码:<input type="password" id="password1"/><br/>
<button id="btn" type="button">提交</button><br/>
</body>

 答案:

 <script>
$(document).ready(function(e){
$("button").click(function(){
if($("#username").val()==""){
alert(" 1");
}
if($("#password").val().length){
alert("2 ");
}
})
})
</script>

5.在下面的HTML文档中,编写函数test() ,实现如下功能:

(1)当多行文本框中的字符数超过20个,截取至20个

(2)在id为number的td中显示文本框的字符个数

 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言</title>
</head>
<body>
<table>
<tr>
<td>留言</td>
<td id="number"> 0 </td>
</tr>
<tr>
<td colspan=2>
<textarea id="feedBack" onkeyup="test()" rows=6></textarea>
</td>
</tr>
</table>
</body>
</html>

答案:

 <script>
var $a=$("#number");
var b=document.getElementById("feedBack")
function test(){
if(b.value.length>20){
b.value=b.value.substring(0,20)
}
$a.text(b.value.length);
}
</script>

6.要求用javascript完成下图的功能

根据题意写出checkInput和update函数的实现

checkInput函数功能为,当前输入框内容不为数字的时候要警告,返回后,文本框内容应处于选中状态

 <body>
<table id="t" border="1px">
<caption>甲骨文练习</caption>
<tr>
<td>HTML</td>
<td>JavaScript</td>
</tr>
<tr>
<td>JavaSE</td>
<td>Oracle</td>
</tr>
<tr>
<td>MySQL</td>
<td>Struts2</td>
</tr>
</table><br>
设置指定单元格的值:<br/>
第<input type="text" id="r" onblur="checkInput(this)">行,<br/>
第<input type="text" id="c" onblur="checkInput(this)">列<br/>
的值为<input type="text" id="q" > <br/>
<input type="button" value="修改" onClick="update()">
</body>

答案:

 <script>
function checkInput(a){
var a=/^[0-9]*$/;
if(!angular.test(a.value)){
alert("请输入数字");
}
}
function update(){
var r=document.getElementById("r").value;
var c=document.getElementById("c").value;
var val=document.getElementById("q").value;
document.getElementById("t").rows[r-1].cells[c-1].innerHTML=val;
}
</script>

7.实现getOptions函数,点击按钮把选中内容输出在按钮下方。

 <body>
<form>
Select your favorite fruit:
<select id="mySelect" multiple="multiple" size="4">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="getOptions()"
value="Output all options">
<div id="allselect"></div>
</form>
</body>

答案:

 <script>
function getOptions(){
$("option:checked").each(function(){
alert($(this).val())
})
}
</script>

8.实现sel函数显示当前选项的文本和值。

 <form name="a">
<select name="a" size="1" onchange="_sel(this)">
<option value="a">1</option>
<option value="b">2</option>
<option value="c">3</option>
</select>
</form>

答案:

 <script>
function _sel(a){
alert($("option:checked").text()+$("option:checked").val())
}
</script>

JAVASCRIPT试题及答案的更多相关文章

  1. 前端周报:前端面试题及答案总结;JavaScript参数传递的深入理解

    1.2017前端面试题及答案总结 |掘金技术征文 "金三银四,金九银十",用来形容求职最好的几个月.但是随着行业的饱和,初中级前端er就业形势不容乐观. 行业状态不可控,我们能做的 ...

  2. 56 道高频 JavaScript 与 ES6+ 的面试题及答案

    56 道高频 JavaScript 与 ES6+ 的面试题及答案 :https://segmentfault.com/a/1190000020082089?utm_source=weekly& ...

  3. Android 面试题及答案(2)

    1.Activity相关.launchmode,OnSaveInstnceState,生命周期等. 4种默认的launchmode,以及OnNewIntent的回调. OnNewIntent-> ...

  4. php面试题及答案收藏(转)

    php面试题及答案收藏(这套试题是在网上看到的,不知作者是谁) 基础题 1.表单中 get与post提交方法的区别? 答:get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据, ...

  5. jQuery经典面试题及答案精选(转)

    jQuery是一款非常流行的Javascript框架,如果你想要从事Web前端开发这个岗位,那么jQuery是你必须掌握而且能够熟练应用的一门技术.本文整理了一些关于jQuery的经典面试题及答案,分 ...

  6. 2016最全的web前端面试题及答案整理

    面试web前端开发,不管是笔试还是面试,都会涉及到各种专业技术问题,今天小编整理了一些常见的web前端面试题及答案,希望对大家有所帮助. 1.常用那几种浏览器测试?有哪些内核(Layout Engin ...

  7. 近5年常考Java面试题及答案整理(三)

    上一篇:近5年常考Java面试题及答案整理(二) 68.Java中如何实现序列化,有什么意义? 答:序列化就是一种用来处理对象流的机制,所谓对象流也就是将对象的内容进行流化.可以对流化后的对象进行读写 ...

  8. 近5年常考Java面试题及答案整理(二)

    上一篇:近5年常考Java面试题及答案整理(一) 31.String s = new String("xyz");创建了几个字符串对象? 答:两个对象,一个是静态区的"x ...

  9. PHP面试题及答案解析(8)—PHP综合应用题

    1.写出下列服务的用途和默认端口. ftp.ssh.http.telnet.https ftp:File Transfer Protocol,文件传输协议,是应用层的协议,它基于传输层,为用户服务,它 ...

随机推荐

  1. 十进制快速幂(牛客多校第五场)-- generator 1

    思路: 十进制快速幂. #include <stdio.h>//sprintf #include <cstdlib>////malloc exit strcat itoa sy ...

  2. C++练习 | 文件流应用(1)

    #include <iostream> #include <cmath> #include <cstring> #include <string> #i ...

  3. vscode 插件 配置

    第一页 第二页 第三页 settings.json配置 { "editor.fontSize": 20, "files.autoSave": "off ...

  4. maven项目转换为gradle项目

    进入到项目更目录,运行 gradle init --type pom 上面的命令会根据pom文件自动生成gradle项目所需的文件和配置,然后以gradle项目重新导入即可.

  5. js三级内联

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. the Percentage Layout of Android (安卓的百分比布局)

    不用wrap_content.match_parent来指定 控件的大小, 1.在app/bulid.gradle文件的dependencies中添加 compile 'com.android.sup ...

  7. C# 过滤字典中的数据 并将过滤后的数据转成新的字典对象

    Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("); dic. ...

  8. 【异常】~/.bash_profile:source:44: no such file or directory: /usr/local/Cellar/nvm/0.34.0/nvm.sh

    1 异常信息 /Users/zhangjin/.bash_profile:source:: no such file or directory: /usr/local/Cellar/nvm//nvm. ...

  9. 外星人电脑出现the system is running in low graphics mode的解决方法

    问题现象: 执行删除GCC5.4.0: sudo  apt-get remove gcc gcc-5重启电脑后,就显示the system is running in low graphics mod ...

  10. 了解并安装Nginx

    公司使用nginx作为请求分发服务器,发现本人在查看nginx配置上存在些许困难,故仔细阅读了陶辉的<深入理解nginx模块开发与框架>第一部分,并作此记录. 了解 我根据书上的思路来了解 ...