我只是对我发现的这个JS感到好奇
I'm just curious about this JS I found
我在某处找到了这个Javascript,想学习。因此,我只会对我不知道的问题提出问题。
1)我想知道为什么构建器变量有主题标签。
(function($) {
$(document).ready(function() {
'use strict';
var builder = $('#builder');
2)似乎写在那里的建造者与 #builder 有关......
/**
* Gets the json for the form in the embedded builder.
*
* @return string the form's json.
*/
var getFormDocument = function() {
if (document.getElementById('builder').contentWindow.getFormDocument == null) {
return '{}';
}
return document.getElementById('builder').contentWindow.getFormDocument();
};
3)再次,这里的哈希标签。是来自 css 吗?
/**
* Adjusts the builder's height to the window.
*/
var resizer = function() {
var w = $(window).height(),
h = $('header').height(),
t = $('#top-row').height(),
p = 12, // top padding
o = (w - h - t - p) + 'px';
builder.css('height', o);
};
4) .js表单文档是 JQuery 的功能之一吗?
/**
* Called when the user is done building their form.
*/
var clickedSave = false;
var save = function() {
clickedSave = true;
jQuery('.js-form-document').val(getFormDocument());
jQuery('#builderModal_signup').reveal();
};
5)为什么有TODO说iframe会发疯?在用户保存表单后,这个js代码如何连接到数据库?
/**
* Adds listeners for the embedded builder and keeps the
* builder properly positioned.
*/
var init = function() {
// TODO: iframe width at 100% goes bonkers.
var width = $($('div.twelve.columns')[0]).width();
builder.css('display', 'block');
builder.css('width', width + 'px');
$('.js-save').click(save);
};
var hasFields = function() {
var formDocument = JSON.parse(getFormDocument());
if (formDocument.fields == null) {
return false;
}
var sections = formDocument.fields;
if (sections.length === 0 || sections[0].fields.length === 0) {
return false;
} else {
return true;
}
};
6)不明白这里的哈希标签是什么意思...
/*
* Triggers a call to action for the user
*/
var firstCallout = function() {
if (clickedSave) {
return;
}
if (!hasFields()) {
jQuery('#builderModal_noFields').reveal();
} else {
jQuery('#builderModal_hasFields').reveal();
}
};
init();
setTimeout(function(){firstCallout();}, 30000);
setInterval(function() {
var onClass = $('.js-save').attr('data-on-class');
if (onClass === '') {
onClass = 'green';
}
if (hasFields()) {
$('.js-save').removeClass('gray').addClass(onClass);
} else {
$('.js-save').removeClass(onClass).addClass('gray');
}
}, 1000);
});
})(jQuery);
var lastHeight = 0;
function resizeBuilder() {
setInterval(function() {
var iframe = document.getElementById('builder');
var padding = 20;
var height = iframe.contentWindow.document.body.scrollHeight;
//chrome counts padding in scroll height and creates never ending height
if (Math.abs(height - lastHeight) <= padding) {
return;
}
height += padding;
if (height < 400) {
height = 400;
}
iframe.height = height + 'px';
lastHeight = height;
}, 1000);
}
显然你缺乏jQuery的基本知识。哈希代表 DOM 元素 ID 的选择器,点代表类选择器。关于"TODO" - 这看起来像是开发人员在受够了 iframe 后的评论。为什么它会在 100% 上发疯?毫无头绪。
表单正在由客户端脚本与之通信的某些服务器端脚本/代码处理(阅读有关 AJAX 的更多信息)。
希望澄清一点,祝你今天开心
不是"hashtag"是一个CSS选择器,他通过id"builder"选择对象
在 CSS 中,您可以使用此语法选择内容。
- "#" 按 ID
- "." 按类
- "sometag",没有特殊的caracter,这意味着您正在选择一个标签(或一堆标签)。
使用标签、类或 id,您可以使用以下属性在选择中执行
"div[name=mydiv]"。
希望对您有所帮助。
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 使用agility.js进行页面布局和合成
- 使用Clipboard.js复制span文本
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 强制模板刷新ember.js
- 如何编写HTML输入的JS内联
- Angular JS IE9 Hashbang url rewriting
- 使用JS将数组转换为json对象
- Node.js v6.2.0类扩展不是函数错误
- 当js函数's已执行
- 要求未定义JS回调参数
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 如何从Java/scala调用js美化程序
- 如何更改<svg>标记为<img>用js标记
- 如何使用 node.js 比较两个 json 数组
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- 我只是对我发现的这个JS感到好奇
- 好奇!js 链接在文件末尾不起作用