假设我在javascripts中有类似的东西:
var obj = {
subObj : {}
};
var type = 'subObj';
Run Code Online (Sandbox Code Playgroud)
我怎么能得到obj's
subObj
w/type
?例如,我想做的事情如下:
obj.(type);
Run Code Online (Sandbox Code Playgroud) 我在Javascript中并不完美.我想在名为total的下一个输入框中显示在qty输入框中输入的值的总和而不刷新页面.任何人都可以帮我弄清楚..?
这是javascript
<script type="text/javascript">
var howmanytoadd = 2;
var rows;
function calc() {
var tot = 0;
for (var i = 0; i < rows.length; i++) {
var linetot = 0;
rows[i].getElementsByTagName('input')[howmanytoadd].value = linetot;
tot += linetot;
}
document.getElementById('total').value = tot
}
onload = function () {
rows = document.getElementById('tab').getElementById('qty1');
for (var i = 0; i < rows.length; i++) {
rows.getElementsByTagName('input')[i].onkeyup = calc;
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的HTML代码:
Qty1 : <input type="text" name="qty1" id="qty"/><br>
Qty2 : <input type="text" name="qty2" id="qty"/><br>
Qty3 …
Run Code Online (Sandbox Code Playgroud) 我在托架中逃脱的规则是否与我在括号外的操作不同?
例如,我应该逃离?
支架内部吗?是它/blah[^?]/
还是/blah[^\?]/
括号的规则是否不同,或者我是否应该同时逃避?
我希望能够检查url是否包含单词目录.
这就是我想要的......
$(document).ready(function () {
if (window.location.href.indexOf("catalogue"))
{
$("#trail").toggle();
}
});
Run Code Online (Sandbox Code Playgroud)
该网站的网址可能是..
http://site.co.uk/catalogue/
Run Code Online (Sandbox Code Playgroud)
要么
http://site.co.uk/catalogue/2/domestic-rainwater.html
Run Code Online (Sandbox Code Playgroud)
等等
但它不起作用.有人可以指出我哪里出错了吗?
我经常看到this
在jquery 中使用关键字的示例.有时我看到它与$和括号一起使用,有时没有.而且我以为我看到它与每个都用了一点.
所以,
var id = this.attr('id');
var id = $(this).attr('id');
var id = $this.attr('id');
Run Code Online (Sandbox Code Playgroud)
这些都一样吗?有首选方式吗?是this
javascript的东西和$(this)
jQuery的东西?如果是这样,哪里$this
下降?
我知道这可能是一个全新的问题,但我无法让简单的,this
单独的,工作.我只能$(this)
上班.我不确定我做错了什么,或者我是否一直在阅读错别字的例子.
我有以下列表:
<ul id="list">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
如何使用jQuery删除此列表的第一个元素(即数字1)并保留其余元素?
我认为这有一个非常简单的解决方案,但它证明比我预期的更难回答.
我有div
很多孩子.如何div
使用jQuery
?将所有这些移动到另一个?
我的代码看起来像:
jQuery("body").append("<div id='popupWrapper'></div>");
var myID = $('.FloatingFrameLightBlue1').attr('id');
jQuery(myID).children().append("popupWrapper");
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我做错了什么?
第二个警报命令的代码按预期工作(显示元素"to"的值,但第一个警告命令不起作用(它应该做同样的事情).为什么这个?
<html>
<head>
<script type="text/javascript">
function getValue()
{
alert(document.getElementsByName("to").value);
alert(document.forms[0].to.value);
}
</script>
</head>
<body>
<form>
<input name="to" type="hidden" value="hoolah" />
<input type="button" onclick="getValue()" value="Get Value!" />
<form/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 为什么这种行为parseInt()
与parseFloat()
?之间存在差异?
我有一个包含08
在其中的字符串.
当我写这段代码时:
alert(hfrom[0]);
alert(parseInt(hfrom[0]));
alert(parseFloat(hfrom[0]));
Run Code Online (Sandbox Code Playgroud)
生成以下输出:
08
0
8
Run Code Online (Sandbox Code Playgroud)
为什么parseInt
和parseFloat
在这种情况下返回两个不同的结果?
我正在使用以下JavaScript代码警告用户,如果他尝试重定向到另一个页面而不提交表单.
window.onbeforeunload = function() {
return 'Are you sure that you want to leave this page?';
};
Run Code Online (Sandbox Code Playgroud)
这工作正常.但我的问题是当用户尝试使用提交按钮确认框提交表单时将出现.我不想询问用户是否提交表格,否则我想要确认.这怎么可能?