我试图从我在表单中获得的变量创建一个json对象.
var firstName = $('#firstName').val();
var lastName = $('#lastName').val();
var phone = $('#phoneNumber').val();
var address = $('#address').val();
Run Code Online (Sandbox Code Playgroud)
到目前为止,我有下面的代码,但它不会验证或工作.我是新手,请帮忙!将var更改为:
var jsonObject =
{
firstName: firstName,
lastName: lastName,
phoneNumber:phoneNumber,
address:address
}
Run Code Online (Sandbox Code Playgroud)
在JSONlint我收到此错误:
第1行的解析错误:varjsonObject = {
^期待'{','['
我有以下标记:
<a href="#" title="Feedback" id="feedbacktogglenav">
Feedback
<i class="icon-comment"></i>
</a>
Run Code Online (Sandbox Code Playgroud)
在悬停时,我希望文本加下划线但不是字体 - 真棒图标.我知道你可以在图标上进行"text-decoration:none"(可以正常工作)但是当你将鼠标悬停在文本部分时,它仍然会在图标上添加下划线.有任何想法吗?
如果值超过100,我希望阻止用户输入更多内容.到目前为止,我在阅读不同帖子时有以下内容:
$('.equipCatValidation').keyup(function(e){
if ($(this).val() > 100) {
e.preventDefault();
}
});
Run Code Online (Sandbox Code Playgroud)
要确认我希望值不是字符串长度,并且它不能超过100.
然而,这并不妨碍该领域的进一步投入.我错过了什么
我正在尝试重新格式化我从API获取的日期.在我拥有的对象中:
created_at: "2013-06-13T16:29:55.245Z"
Run Code Online (Sandbox Code Playgroud)
我想将日期显示为2013年6月13日.有人建议我用moment.js.它有大量的文档,但我对如何使用它有点困惑.有人可以帮助或建议一个更简单的方法吗?
我需要阻止用户在我正在构建的应用程序的某些部分进行向后导航.到目前为止,我正在使用这种方法:
ngOnInit() {
history.pushState(null, null, location.href);
window.onpopstate = function(event) {
history.go(1);
};
}
ngOnDestroy() {
window.onpopstate = function(event) {
history.go();
};
}
Run Code Online (Sandbox Code Playgroud)
除了iOS chrome和safari之外,这项工作非常有效.我也尝试过:
history.replaceState(null, document.title, location.pathname);
Run Code Online (Sandbox Code Playgroud)
在ngOnInit没有运气.有人可以告诉我这些移动设备上的浏览器如何使用历史记录和/或popstate不同于Windows/macOS版本的浏览器?
当点击"赞"按钮时,我试图在两个函数之间切换.
<div class="like">
<div class="count"><%= post.num_likes %> </div>
<div class="icon" id="like"><i class="icon-thumbs-up-alt"></i></div>
</div>
Run Code Online (Sandbox Code Playgroud)
现在我有:
$(".like").click(function(event){
event.stopPropagation();
$("i", this).toggleClass("icon-thumbs-up-alt").toggleClass("icon icon-thumbs-up");
likePost(TestCanvas, $(this).prev('div').find('.hideThis').text());
});
Run Code Online (Sandbox Code Playgroud)
likePost(canvasID,postID)接受参数并与API交互当我再次单击.like时,我想调用differentPost().
当单击.like时,是否有一种简单的方法可以在likePost()和differentPost()之间切换?
我试过了:
$('.like').toggle(function() {
alert('First handler for .toggle() called.');
likePost(TestCanvas, $(this).prev('div').find('.hideThis').text());
}, function() {
alert('Second handler for .toggle() called.');
unlikePost(TestCanvas, $(this).prev('div').find('.hideThis').text());
});
Run Code Online (Sandbox Code Playgroud)
它没有像我想的那样工作.似乎在页面加载时执行而不是单击.like.
我正在切换我的服务调用以使用新的HttpClient.我正在努力做三件事
application.component.ts
this.applicationFormService.putForm(formModel)
.subscribe(
// Successful responses call the first callback.
(res) => this.goToRoute(res),
// Errors will call this callback instead:
(err: HttpErrorResponse) => {
if (err.error instanceof Error) {
console.log("Client-side error occured.");
} else {
console.log("Server-side error occured.");
}
},
//Tried adding progress event logic here but I get error Argument of type '(event: any) => void' is not assignable to parameter of type '() => void'. Is this totally the wrong implementation and can it …Run Code Online (Sandbox Code Playgroud) 下划线让我难过!在我的代码中,一切都与$ .when之后获取数据有关.console.log(帖子); 但是当我尝试将其传递给模板和参考时
<h1><%=posts.id %></h1>
Run Code Online (Sandbox Code Playgroud)
我在网上得到"Uncaught ReferenceError:posts not defined"
$("#target").html(_.template(template,posts));
Run Code Online (Sandbox Code Playgroud)
这是整个页面
<!DOCTYPE html>
<html>
<head>
<script src="js/api.js"></script>
<link href="css/styles.css" media="" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="target"></div>
<!-- BEGIN: Underscore Template Definition. -->
<script type="text/template" id="template">
<h1><%=posts.id %></h1>
</script>
<!-- END: Underscore Template Definition. -->
<!-- Include and run scripts. -->
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/underscore.js"></script>
<script type="text/javascript">
$.when(results).done(function(posts){
var template = $("#template").html();
console.log(posts);
$("#target").html(_.template(template,posts)
);
});
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
[Object]
0: Object
created_at: "2013-04"
id: "444556663333"
num_comments: 1
num_likes: 0
text: …Run Code Online (Sandbox Code Playgroud) 我需要添加一个结束图像标签。当前的 html:
<img class="logoEmail" src="/images/logoPDF.png">
Run Code Online (Sandbox Code Playgroud)
我想要的是:
<img class="logoEmail" src="/images/logoPDF.png"/>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我试图使用.data从属性中获取值.
HTML
<div class="like" data-postid="903282304865jh"> </div>
Run Code Online (Sandbox Code Playgroud)
JS
$(".like").click(function(event){
var postID = $(event.target).data('postid');
console.log(postID);
});
Run Code Online (Sandbox Code Playgroud)
我在控制台中返回未定义的内容.这里发生了什么?