我需要动态设置JS对象属性名称.
for(i=1; i<3; i++) {
var key = i+'name';
data = {
key : 'name1',
}
}
Run Code Online (Sandbox Code Playgroud)
结果应该是:
data = {
1name: 'name1'
2name: 'name1'
}
Run Code Online (Sandbox Code Playgroud) 我传递了以下对象:
var myVar = { typeA: { option1: "one", option2: "two" } }
Run Code Online (Sandbox Code Playgroud)
我希望能够typeA
从上面的结构中取出密钥.
这个值每次都可以改变,以便下次可以typeB
.
所以我想知道是否有办法让我做类似下面的伪代码:
var theTypeIs = myVar.key();
Run Code Online (Sandbox Code Playgroud)
这种方式,当我可以传递这个对象,我可以拉出对象的第一个值,在这种情况下它是typeA
然后基于我可以用option1
和做不同的事情option2
.
我正在尝试使用j查询$ .ajax方法向我的PHP脚本发送多个数据,但是当我连接多个数据时我只能传递单个数据我在我的php脚本中得到未定义的索引错误意味着发出了ajax请求但数据不是发送我需要知道我应该如何格式化多个数据,以便连续发送到处理脚本名称值对这里是我写的
<script>
$(document).ready(function() {
$('#add').click(function () {
var name = $('#add').attr("data_id");
var id = $('#add').attr("uid");
var data = 'id='+ id & 'name='+ name; // this where i add multiple data using ' & '
$.ajax({
type:"GET",
cache:false,
url:"welcome.php",
data:data, // multiple data sent using ajax
success: function (html) {
$('#add').val('data sent sent');
$('#msg').html(html);
}
});
return false;
});
});
</script>
<span>
<input type="button" class="gray_button" value="send data" id="add" data_id="1234" uid="4567" />
</span>
<span id="msg"></span>
Run Code Online (Sandbox Code Playgroud) 我认为这是一个奇怪的问题,但我不得不问......
如果我有一个看起来像这样的js对象:
$scope.obj1 = {
"name":"John",
"number":"Eleven",
"color":"Red"
}
Run Code Online (Sandbox Code Playgroud)
有没有办法删除整个财产?没有重新赋值给新对象 ..所以如果我想摆脱"number":"Eleven",
我希望对象看起来像这样......
$scope.obj1 = {
"name":"John",
"color":"Red"
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我使用PHPstorm IDE,并希望找到一个格式化JSON的插件,以便我更容易阅读.
目前我在IDE中显示的文件中有这个:
{"property":"value1","property2":"value2","array1":[{"attr1":"value1"},{"attr2":"value2"}]}
Run Code Online (Sandbox Code Playgroud)
我想要一个可以运行的插件,以便我可以看一下:
{
"property": "value1",
"property2": "value2",
"array1": [
{
"attr1": "value1"
},{
"attr2": "value2"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我找到了以下插件,但它似乎不适用于PHPStorm:http://plugins.jetbrains.com/plugin/3964?pr =
这是我的div:
<div id="demo" align="center" value="1">
<h3>By Color</h3>
<input type="radio" name="group1" id="color1" value="#990000" onClick="changeColor()"/><label for="color1">Red</label>
<input type="radio" name="group1" id="color2" value="#009900" onClick="changeColor()"/><label for="color2">Green</label>
<input type="radio" name="group1" id="color3" value="#FFFF00" onClick="changeColor()" /><label for="color3">Yellow</label><br><br><br>
</div>
Run Code Online (Sandbox Code Playgroud)
我想要该div的value属性(value ="1").
我这样想:
function overlay()
{
var cookieValue = document.getElementById("demo").value;
alert(cookieValue);
}
Run Code Online (Sandbox Code Playgroud)
但它显示"未定义"如何使用JavaScript获取值1请建议任何解决方案,.
我有一个像这样的JSON数组:
_htaItems = [
{"ID":1,
"parentColumnSortID":"0",
"description":"Precondition",
"columnSortID":"1",
"itemType":0},
{"ID":2,
"parentColumnSortID":"0",
"description":"Precondition",
"columnSortID":"1",
"itemType":0}]
Run Code Online (Sandbox Code Playgroud)
我想通过将ID,列名和新值传递给函数来更新它:
function updateJSON(ID, columnName, newValue)
{
var i = 0;
for (i = 0; i < _htaItems.length; i++)
{
if (_htaItems[i].ID == ID)
{
?????
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何更新价值?我知道我可以做以下事情:
_htaItems[x].description = 'New Value'
Run Code Online (Sandbox Code Playgroud)
但在我的原因中,列名称作为字符串传递.
我将在我的PhoneGap应用程序中实现注销按钮,该应用程序将用户返回到认证页面(带有已清除的字段).对于按钮我正在使用onclick事件的锚点:
<script type="text/javascript">
function doLogout() {
var backlen = history.length;
history.go(-backlen);
window.location.replace("index.html");
}
</script>
<a data-role="none" href="#" onclick="doLogout"></a>
Run Code Online (Sandbox Code Playgroud)
但它不起作用,即它只是让我回到已经填充的文件的认证页面,似乎只是后退一步.我不确定history.clear(),因为谷歌搜索它没有给我任何东西:
<a data-role="none" href="index.html" onclick="javascript:history.clear();"></a>
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我的问题在哪里?如果有其他解决方案来处理PhoneGap中的注销事件,我会遵循它.谢谢
我知道自动跟踪重定向,并且我很少/无法控制该过程.这很好,但我仍然对我的请求最终结束的地方非常感兴趣.是否有可能看到我的请求最终到底是什么网址?
我不希望靠返回的HTML本身告诉我,我在哪里.
示例代码:
var originalURL = '/this/will/be/redirected';
$.ajax({
url: originalURL,
dataType: "html",
success: function(data, statusText, jqXHR) {
var endPointURL = insertMagicHere();
alert("Our query to " + original + " ended up at " + endPointURL + "!");
}
});
Run Code Online (Sandbox Code Playgroud)
我在jqXHR中寻找它,但到目前为止没有运气.(虽然,我对这一切都是新手,可能就在我的鼻子底下)
我有一个用户需要输入数据的网页.一旦他们输入10个项目,他们就可以继续.
我正在尝试创建一个进度条,以直观地表示他们输入/已经输入的项目数量.
这是我正在尝试创建的图像
到目前为止,我最接近的是使用Bootstrap的堆叠进度条.但是,对于堆叠条,未填充的区域是单个不间断区域 - 它不显示剩余的区段数.这是一个显示我的意思的小提琴.
这是小提琴的标记:
<div class="container">
<div class="progress progress-bar-segmented">
<div class="progress-bar" style="width: 10%"></div>
<div class="progress-bar" style="width: 10%"></div>
<div class="progress-bar" style="width: 10%"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我搜索过类似的例子,可以根据我的需要进行调整,但运气不好.我也不确定我应该搜索什么或者称之为什么.也许这会被认为是一个逐步进步的酒吧?
任何提出解决方案的帮助都将不胜感激.