Цитата:
|
сделал пример на jsfiddle.net http://jsfiddle.net/u4no7dwj/
|
Цитата:
|
forcej,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(function(){
function Dobj(d_class) {
this.dTitle = $(d_class + " h1");
this.dBody = $(d_class + " p");
this.move = function() {
$(this.dBody).toggle()
}
$(this.dTitle).click(this.move.bind(this))
$(this.dTitle).trigger('click')
}
var d = new Dobj(".d_class")
});
</script>
</head>
<body class="d_class">
<h1>click</h1>
<p>hide</p>
</body>
</html>
|
Цитата:
<!DOCTYPE html>
<html>
<head>
<script src='http://code.jquery.com/jquery-latest.js'></script>
<!--
<script src="https://code.angularjs.org/1.3.9/angular.min.js"></script>
<script src="https://code.angularjs.org/1.3.9/angular-route.js"></script>
<link rel='stylesheet type=text/css href=tmp.css' />
-->
<style type='text/css'>
</style>
<script type='text/javascript'>
function Dobj(d_class) {
this.cont = $(d_class)
this.dTitle = this.cont.find("h1")
this.dBody = this.cont.find("p");
var o=this.dBody;
this.move = function() {
alert(this.dBody)
o.hide();
};
$(this.dTitle).click(this.move);
};
$(function(){
var d = new Dobj(".d_class")
});
</script>
</head>
<div class="d_class">
<h1>TITLE</h1>
<P>
содержимое<br>
</P>
</div>
</body>
</html>
P.S. Перестань пихать жиквери-элементы в жиквери... ;) |
ksa, Понял, проблема в области видимости. Спасибо.
|
рони, $(this.dTitle).click(this.move.bind(this)) вы немогли бы чуть более подробно объяснить как это работает?
|
Цитата:
http://learn.javascript.ru/bind |
Цитата:
Привязка контекста (this) к функции в javascript и частичное применение функций |
Цитата:
Цитата:
|
| Часовой пояс GMT +3, время: 21:00. |