如何使用JavaScript删除字符串中的双重或多重下划线?
例如
stack__overflow___website
我需要消除__它并用一个替换它_.
我有一个字符串,其中以空格分隔的唯一数字如下:
"2 4 13 14 28 33"
Run Code Online (Sandbox Code Playgroud)
需要一种快速有效的方式来切换它们的形式:
switchNumbers(2, 28)
// result: "28 4 13 14 2 33"
Run Code Online (Sandbox Code Playgroud)
我可以分割字符串并搜索值,但这听起来很无聊.有什么好主意吗?
我有一个 python 代码,它将普通的 dict 转换为 JSON,如下所示
groups = {
'g_1': [
{'name': 'something', 'id': '1'},
{'name': 'something', 'id': '1'}
],
'g_2': [
{'name': 'something', 'id': '1'},
{'name': 'something', 'id': '1'}
]
}
Run Code Online (Sandbox Code Playgroud)
我使用 json.dumps 将其转换为 json,如下所示
import json
groups = json.dumps(groups)
Run Code Online (Sandbox Code Playgroud)
我想将 javascript 中的数据作为对象读取。我如何访问它?
我试过var groups=JSON.parse({{ groups }})没有成功。帮助我将数据解析为 javascript 对象。
给定这两个字符串:
\n\nvar a = "November 5, 1916";\nvar b = "October 5\xe2\x80\x9310, 1592";\nRun Code Online (Sandbox Code Playgroud)\n\n我在做:
\n\nb.replace(\' \', \'\').split(\' \');\na.replace(\' \', \'\').split(\' \');\nRun Code Online (Sandbox Code Playgroud)\n\n但我仍然得到一个逗号并且没有空格。我需要能够从这些字符串中删除所有逗号并保留空格,以便:
\n\nvar resultA = "November 5 1916";\nvar resultB = "October 5\xe2\x80\x9310 1592";\nRun Code Online (Sandbox Code Playgroud)\n\n更新
\n\n我确实需要split()之后的内容,因为我需要数组中的每个字符串。
有没有办法使用casperjs或phantomjs保存当前的网页?我试图获取html并将其保存到文件中.但是生成的文件与当时的截图(with casper.capture)有很大不同.有没有办法保存当前的网页?
我在替换javascript / jquery中的字符串时遇到了一个小问题。首先代码:
HTML:
<fieldset>
<legend>Contact persons</legend>
<div id="cm_contactPersons">
<fieldset id="cm_%email%">
<legend><span class="glyphicon glyphicon-circle-arrow-right"></span> %email%</legend>
<div class="form-group">
<label for="cm_%email_inputFirstname" class="col-sm-2 control-label">Firstname</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="cm_%email%_inputFirstname" value="%firstname%" placeholder="" required>
</div>
</div>
<div class="form-group">
<label for="cm_%email%_inputLastname" class="col-sm-2 control-label">Lastname</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="cm_%email%_inputLastname" value="%lastname%" placeholder="i. e. Max" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Actions</label>
<div class="col-sm-10">
<button type="button" class="btn btn-warning">Create new password</button>
<button type="button" class="btn btn-danger">Delete contact person</button>
</div>
</div>
</fieldset>
</div>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
Javascript:
$(document).ready(function() {
$('#cm_customerList').btsListFilter('#cm_customerSearchInput');
var …Run Code Online (Sandbox Code Playgroud) 我正在迭代html文档中的所有文本节点,以包围具有特定范围的一些单词.
更改nodeValue不允许我插入HTML.将span被转义为明文显示,我不希望出现这种情况.
这是我到目前为止:
var elements = document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
for (var j = 0; j < element.childNodes.length; j++) {
var node = element.childNodes[j];
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.replace(/Questions/, "<span>Questions</span>");
}
}
}Run Code Online (Sandbox Code Playgroud)
<p>Questions1</p>
<p>Questions 2</p>
<p>Questions 3</p>
<p>Questions 4</p>Run Code Online (Sandbox Code Playgroud)
如何;使用JavaScript从字符串中删除分号()?
例如:
var str = '<div id="confirmMsg" style="margin-top: -5px;">'
Run Code Online (Sandbox Code Playgroud)
如何从中删除分号str?
在我的一个角度应用程序中,当我在ng-repeat中传递键时,我将得到值.
这里,每个排在rowsdata具有类似值'my file1 data', 'my file2 data', 'my file3 data'
但我需要传递它 'myfile1data', 'myfile2data', 'myfile3data'
当我使用rows.replace('','')时,它只删除第一个空格 'myfile1 data', 'myfile2 data', 'myfile3 data'
<tr ng-repeat="data in datas">
<td ng-repeat="rows in rowdatas">{{data[rows.replace(' ','')]}}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
编辑
但是当我使用时
<td ng-repeat="rows in rowdatas">{{data[rows.replace(/ /g,'')]}}</td>
Run Code Online (Sandbox Code Playgroud)
我有
Error: a is not a function OPERATORS["/"]@http://loclhost/jcp_standardwork/secure/scripts/vendor/angular/a??ngular.js:5959 OPERATORS["/"]@http://loclhost/jcp_standardwork/secure/scripts/vendor/angular/a??ngular.js:5959 binaryFn/<@http://loclhost/jcp_standardwork/secure/scripts/vendor/angular/angul??ar.js:6292
Run Code Online (Sandbox Code Playgroud)
有人能告诉我一些解决方案吗?
假设我有:
<h1>Win $50<h1>
Run Code Online (Sandbox Code Playgroud)
我需要使用jQuery将$符号更改为€,
所以我可以这样做:
$('h1').text( $('h1').text().replace('$', '€') );
Run Code Online (Sandbox Code Playgroud)
但是,如果我有类似的事情怎么办:
<h1>Win $50 and Get $100</h1>
Run Code Online (Sandbox Code Playgroud)
它只会更改第一个,如何更改所有内容?