我有一个示例段落文本p tag.如果我在段落中选择一些文字.我正在将其文本颜色从黑色更改为绿色并将其包装为span tag添加为其选择的类.但我可以选择已经选择的文本.我不希望再次选择所选文本.
我在链接中给出了示例代码:http://jsfiddle.net/2w35p/81/
function getSelectedText() {
t = (document.all) ? document.selection.createRange().text : document.getSelection();
return t;
}
$('body').mouseup(function() {
var selection = getSelectedText();
var selection_text = selection.toString();
var span = document.createElement('SPAN');
span.textContent = selection_text;
span.className = "selectedText"
var range = selection.getRangeAt(0);
range.deleteContents();
range.insertNode(span);
});Run Code Online (Sandbox Code Playgroud)
span {
color: green;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text …Run Code Online (Sandbox Code Playgroud)我有一个Interface find,它包含方法cal(); 类a1和a2实现接口.a1返回一个数字,而a2返回一个数字.如何定义单个界面来解决我的问题.
以下是有上述内容的片段.
interface Ifind {
cal() : string;
}
class a1 implements Ifind{
public cal():string{
return "10";
}
}
class a2 implements Ifind{
public cal(): number{
return 12;
}
}
class main{
private obj;
constructor() {
this.obj = new a1();
var p = this.obj.cal();
alert(p)
}
}
Run Code Online (Sandbox Code Playgroud)
我试图在调整窗口大小时触发一个事件,它似乎不起作用。
$(window).resize(function(){
_.debounce(function(){
console.log("hello");
}, 100);
})
Run Code Online (Sandbox Code Playgroud) 我有一个gulp任务,它使用yargs 接收参数位置。而且我使用webpack为我的应用程序提供入口点
webpackConfig.entry.push('BootStrapper.ts');
Run Code Online (Sandbox Code Playgroud)
我有一个webpack配置,它具有引导程序的入口点。
module.exports = {
entry: [],
output: {
path: require("path").resolve('./dist/'),
filename: 'MyProcess.built.js'
},
}
Run Code Online (Sandbox Code Playgroud)
我想将位置变量传递给Bootstrapper.ts,有没有办法实现?
我sap.m.RadioButton认为有一个群体:
<RadioButtonGroup select=".changeRegion">
<RadioButton id="rb-S" text="S" />
<RadioButton id="rb-MW" text="MW" />
<RadioButton id="rb-NE" text="NE" />
<RadioButton id="rb-W" text="W"/ >
</RadioButtonGroup>
Run Code Online (Sandbox Code Playgroud)
在我的控制器中:
changeRegion: function(e) {
console.log(e.getParameter("selectedIndex"));
},
Run Code Online (Sandbox Code Playgroud)
我能够访问所选单选按钮的索引。有什么方法可以获取所选单选按钮的文本吗?
我试图在打字稿中创建一个类,但它总是抛出下面提到的错误。
下面是执行的日志,它抛出一个错误。
[LOG]: "adding"
[LOG]: undefined
[ERR]: Cannot set property 'hello' of undefined
Run Code Online (Sandbox Code Playgroud)
class CustomDataStructure {
private _data: any;
public CustomDataStructure() {
this._data = {};
}
public addItem(value: string) {
console.log("adding");
console.log(this._data)
this._data[value] = new Date().getTime();
}
public removeItem(key: string) {
delete this._data[key];
}
public showData() {
return this._data;
}
}
let ss = new CustomDataStructure();
ss.addItem("hello");
Run Code Online (Sandbox Code Playgroud) 我有一个字符串*dfgi*kjklx .我想删除输出之前和之后的字符
fgjklx
Run Code Online (Sandbox Code Playgroud)
我已经编写了这样的代码,但它显示了索引超出范围的错误.
String t = "*dfgi*kjklx";
for(int i = 0; i < s.length(); i++)
{
String temp = s.charAt(i);
if(temp == ‘*’)
{
t = t.replace(s.charAt(i), '');
t = t.replace(s.charAt(i-1), '');
t = t.replace(s.charAt(i+1), '');
System.out.println("String: " + t);
}
}
Run Code Online (Sandbox Code Playgroud) javascript ×3
typescript ×3
generics ×1
gulp ×1
java ×1
jquery ×1
lodash ×1
sapui5 ×1
string ×1
webpack ×1