我只是在编写这个脚本,但我无法弄清楚为什么它不会运行!任何帮助赞赏.
使用Javascript
$(document).ready(function() {
var str = document.getElementById('size').innerHTML;
var res = str.replace('<p>','<input type="checkbox" value="');
var res = str.replace('</p>','" id="size" name="size[]" checked />');
document.getElementById('size').innerHTML=res;
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div id="size">
<p>xs</p>
<p>s</p>
<p>m</p>
<p>l</p>
<p>xl</p>
</div>
Run Code Online (Sandbox Code Playgroud)
这是JS小提琴:http://jsfiddle.net/L2LGV/
我有一个宁静的Web服务http:// localhost:8080/CRUDWebAppMavenized/persons,输出一个json数组.我在jquery中使用AJAX,我想在我的HTML表中显示json数组.我不能让它显示在html表中.我将发布html,javascript代码和json数组代码.
index3.html HTML文件.用于在浏览器中显示学生信息.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="engine.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<table id="blogTable">
<tr>
<th>studentId</th>
<th>firstname</th>
<th>lastname</th>
<th>yearLevel</th>
</tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
engine.js(使用Jquery) AJAX调用然后将代码放在html文件的表标记中.
$(document).ready(function () {
$.ajax({
url: 'http://localhost:8080/CRUDWebAppMavenized/persons',
type: 'GET',
dataType: 'json',
success: function (result) {
var insert = '';
$.each(result, function (index, item) {
insert += '<tr><td>' + item.studentId + '</td><td>' + item.firstname + '</td><td>' + item.lastname + '</td><td>' + item.yearLevel + '</td></tr>';
});
$('#blogTable tr:last').after(insert);
}
});
});
Run Code Online (Sandbox Code Playgroud)
JSON数组 …
我正在创建一个网站,我在ascx中有菜单作为组件.
我想把我的班级名改为不同的名字;
这是我的代码:
<div id="mainMenu" style="float: left;">
<ul class="level1 static">
<li class="menu" style="position: relative;">test </li>
<li class="menu" style="position: relative;">test </li>
<li class="menu" style="position: relative;">test </li>
<li class="menu" style="position: relative;">test </li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
对于其中一个页面,我想将自己的样式添加到菜单li中.所以我希望所有课程都改为:
class="apple"
class="grape"
class="bannana"
class="orange"
Run Code Online (Sandbox Code Playgroud)
我将如何在jquery中执行此操作
<script type="text/javascript">
// ?
</script>
Run Code Online (Sandbox Code Playgroud)
我在Ubuntu中使用了sublime-text2editör和chrome web浏览器.这个非常简单的代码无法正常工作但是当我在脚本标签中只编写alert("test")时它正在工作但是这个简单的代码现在不能正常工作.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Scroll Activated Animation</title>
<script type="text/javascript" src="../../jquery-2.1.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#test").click(function(){
alert("test");
});
});
</script>
<style type="text/css" rel="stylesheet">
#test{
width:50px;
height:50px;
background-color: #eee;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="test">Click here</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
jquery源代码没有问题.因为我上面说过只有警报才有效
图片路径:
我正在制作一个在按钮的帮助下切换(隐藏和显示)的表单,但它不起作用.任何人都可以检查我的代码,并告诉我为什么我的脚本不起作用.我的代码如下
$(document).ready(function () {
$("#add_facility").click(function () {
$("#facility-form").toggle('slow');
});
});
Run Code Online (Sandbox Code Playgroud)
.facility-form {
background-color: #e3edfa;
padding: 4px;
cursor: initial;
display: none;
}Run Code Online (Sandbox Code Playgroud)
<button class="btn" id="add_facility">
<i class="fa fa-plus" aria-hidden="true"></i>
Add Facilities
</button>
<div class="facility-form">
<form id="facility-form1">
<div class="row">
<div class="col-md-4">
<div class="checkbox">
<label>
<input type="checkbox" value="">Internet
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" value="">Bar
</label>
</div>
</div>
<div class="col-md-4">
<div class="checkbox">
<label>
<input type="checkbox" value="">Free Wifi
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" value="">Spa
</label>
</div>
</div>
</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
我试图让某些图像的宽度和高度相等(或者更具体:围绕它的div),但不知何故它似乎不起作用..任何可以提供帮助的人?
$('.a2paragraph .image img').each(function() {
var img = $('.a2paragraph .image img');
var h = img.height(),
w = img.width();
if (h > w) {
img.parent().css('height', w);
}
else if (w < h) {
img.parent().css('width', h);
}
});
Run Code Online (Sandbox Code Playgroud)
编辑:更改了代码,但仍然无法正常工作:
$('.a2paragraph .image img').each(function() {
var img2 = $('.a2paragraph .image img');
var h = img2.height(),
w = img2.width();
if (h > w) {
img2.parent().css('height', w);
}
else if (h < w) {
img2.parent().css('width', h);
}
})
Run Code Online (Sandbox Code Playgroud)