我的代码中往往会有很多这些
if(shouldElementBeVisible)
$element.show()
else
$element.hide()
Run Code Online (Sandbox Code Playgroud)
是否有更优雅的方式与javascript,jquery或下划线打包?理想情况下,我想要的东西看起来像这样
$element.showOrHideDependingOn(shouldElementBeVisible)
Run Code Online (Sandbox Code Playgroud) 我的页面中有一个子导航,在公共主视图下方显示一些子视图.我想通过一个对象传递给子视图,<router-outlet>这样我就可以在主组件中检索一次数据,然后与子组件共享它.
注意:如果我<one></one>在main.html中包含该指令,它可以工作,但这不是我想要的行为.
主要观点:
<h1>Details</h1>
<a [router-link]="['./sub1']">One</a> |
<a [router-link]="['./sub2']">Two</a> |
<a [router-link]="['./sub3']">Three</a>
<hr/>
<router-outlet [data]="maindata"></router-outlet>
Run Code Online (Sandbox Code Playgroud)
子视图1:
<h2>{{ data.name }}</h2>
...
Run Code Online (Sandbox Code Playgroud)
主要观点:
@Component({
selector: 'main-detail',
directives: [ROUTER_DIRECTIVES],
templateUrl: './main.html'
})
@RouteConfig([
{ path: '/', redirectTo: '/one' },
{ path: '/one', as: 'One', component: OneComponent },
{ path: '/two', as: 'Two', component: TwoComponent },
{ path: '/three', as: 'Three', component: ThreeComponent }
])
export class MainComponent {
maindata: Object = {name:'jim'};
}
Run Code Online (Sandbox Code Playgroud)
子视图1:
@Component({
selector: 'one', …Run Code Online (Sandbox Code Playgroud) 我有以下jquery事件处理函数:
$('.target').on('dblclick', function() {
//respond to double click event
});
Run Code Online (Sandbox Code Playgroud)
我的问题是这个事件处理程序不适用于触控设备(iPhone,iPad ......).任何人都可以推荐一种可靠的替代品dblclick,可以在触摸设备上使用,并且仍可以在全尺寸设备上轻松双击使用吗?
我正在尝试设置一个Angular2 Observable,它将重放最新的值.
import {Injectable} from 'angular2/core';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class RefinementService {
refining: any;
private r: any;
constructor() {
this.refining = new Observable(observer => this.r = observer).replay(1);
}
}
Run Code Online (Sandbox Code Playgroud)
我不断得到错误说明:
类型Observable <{}>上不存在属性"重放".
和
this.refining.replay不是一个函数
有没有人成功实施过一个可以重新向新用户发放最新价值的观察者?
我想要做的是通过迭代Angular2中已配置路由的列表来动态构建我的导航.我似乎无法在路由器中找到可以访问已配置路由的任何位置.有没有人尝试过这样的事情?
我查看了它Router的registry属性,但似乎没有任何可用的东西.
@Component({
selector: 'my-app'
})
@View({
directives: [ROUTER_DIRECTIVES, CORE_DIRECTIVES],
template: `
<h1>Routing Example</h1>
<div>
<div>
<b>Main menu: </b>
<a [router-link]="['Home']">Home</a> |
<a [router-link]="['One']">One</a> |
<a [router-link]="['Two']">Two</a>
<!--
// I would rather do something like this:
<a *ng-for="#route of router.routes" [router-link]="['route.name']">{{ route.name }}</a>
-->
</div>
<div>
<router-outlet></router-outlet>
</div>
</div>
`
})
@RouteConfig([
{ path: '/', redirectTo: '/home' },
{ path: '/home', as: 'Home', component: Main },
{ path: '/one', as: 'One', component: One },
{ path: …Run Code Online (Sandbox Code Playgroud) 我在移动设备/平板电脑上遇到问题,事件发生两次.当我单击以下功能时,应该下拉的菜单将下拉,然后immediataly滑回.这只是触控设备的问题.
$(document).on("touchend click", ".lines-button", function(e){
e.stopImmediatePropagation();
if($(this).hasClass("close")){
$(this).removeClass("close");
$(".widget1x1Back").next(".actionsHolder3").slideUp("fast", function() {
$(this).remove();
});
}else{
var iconsList = $(this).closest(".top1x1").next(".hdnActnLst").find(".iconsHolder3").html();
$(this).closest(".widget1x1").append(iconsList);
$(this).closest(".widget1x1").find(".actionsHolder3").hide();
$(this).closest(".widget1x1").find(".actionsHolder3").slideDown(700,"easeOutBack");
$(this).addClass("close");
}
});
Run Code Online (Sandbox Code Playgroud)
任何输入都会很棒,谢谢!!
我用JS编写了一个表单验证,以return(true)结尾;
function check() {
....validation code
return(true);
}
Run Code Online (Sandbox Code Playgroud)
我想要的是,需要检查check()函数是否返回true,我想执行另一个函数.
我试过的代码如下:
if(check() === true) {
function() {
//Another function code
}
}
Run Code Online (Sandbox Code Playgroud) 好吧,如果有人能帮助我,我会非常感激.如果您复制并粘贴以下内容并在IE或Firefox中打开
<div style="border: solid 1px navy; float: left;">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
<div style="background-color: blue;">
<p>Some Text</p>
<p>Another paragraph</p>
</div>
Run Code Online (Sandbox Code Playgroud)
为什么具有蓝色背景的第二个div扩展到包含项目列表的第一个div后面?如何让它真正漂浮在第一个div旁边?
我想我在这里做错了,我希望textarea在每一方都比父div小10px,但它不是那样的,它太小了:
<html>
<div style="position: absolute; left: 10px; top: 10px; width:50%; height: 50%; border: 1px solid #000000;">
<textarea style="position: absolute; left: 10px; top: 10px; bottom: 10px; right: 10px; border: 1px solid #FF0000; resize:none;"></textarea>
</div>
</html>
Run Code Online (Sandbox Code Playgroud)
jsfiddle:http://jsfiddle.net/2a7LR/1/
为什么会这样?我怎样才能做到这一点,它从父div的每一侧小10 px?
它只在chrome/safari中正确显示,但在其他所有浏览器中都出错(firefox,opera,IE8)
您可以在当前Web浏览器的HTML标记中使用多个css类,例如:
<div class="style1 style2 style3">foo bar</div>
Run Code Online (Sandbox Code Playgroud)
这并不总是奏效; 哪些版本的主流浏览器开始正确支持此功能?
angular ×3
css ×3
html ×3
javascript ×3
jquery ×3
touch ×2
typescript ×2
browser ×1
events ×1
mobile ×1
routing ×1
rxjs ×1
textarea ×1
visibility ×1