jquery

Javascript plus operator not works with ternary if else

折月煮酒 提交于 2021-02-17 05:13:00
问题 Hi this is my js code. var a = '<span> and have </span>' + $('#module_product_review_star_1 .pdp-link')[1] ? $('#module_product_review_star_1 .pdp-link')[1].outerHTML : 'not have'; alert(a); I'm using ternary operator to check the item exists in dom. But when the item is not in dom this code is failing. this works, if($('#module_product_review_star_1 .pdp-link')[1]){ questiones = '<span> and have </span>' + $('#module_product_review_star_1 .pdp-link')[1].outerHTML; } But I need to use ternary

close side menu when clicked outside

倾然丶 夕夏残阳落幕 提交于 2021-02-17 03:59:25
问题 this is my code for a menu that comes in from the right side... heres is the js jQuery(document).ready(function($) { var $toggleButton = $('.toggle-button'), $menuWrap = $('.menu-wrap'), $sidebarArrow = $('.sidebar-menu-arrow'); $content = $('.content'); // Hamburger button $toggleButton.on('click', function() { $(this).toggleClass('button-open'); $menuWrap.toggleClass('menu-show'); $content.toggleClass('content-background'); }); // Sidebar navigation arrows $sidebarArrow.click(function() { $

Modify a local file with Javascript

ε祈祈猫儿з 提交于 2021-02-17 03:40:55
问题 I must make a local app with an interface. This app should load text files, modify them, and save them. I made the interface with html/css/js, and the core of the app was made with js only. Currently, I load the file with an input, but to save it, the browser makes me download it. I know this is a security measure. This app is not going to be put online. My question is : what can I do to replace directly the loaded file by the new one ? Can I use my app (html/css/js) without a browser ? Is

remove readonly from input

主宰稳场 提交于 2021-02-17 02:52:28
问题 I have a pice of code that copy 2 3 divs and the div contains a readonly property. After that I have a button that says to edit when I click on that button this should remove the readonly and the input field is available to edit. My code that doesn't work! my javascript code: I have tried removeAttr , prop('readonly', false) , attr('readonly', false) $("body").on("click", ".btn",function(){ if($(this).is("#edit")){ $(this).parents(".control-group").removeAttr('readonly'); }else if($(this).is(

Hide an API key from the client side

偶尔善良 提交于 2021-02-17 02:42:27
问题 I am attempting an API integration with Zendesk. I'm having a lot of problems. You can see the questions I've asked about it so far below: How to pass an access token in an ajax call ZenDesk API ticket submission using Javascript - authorization Now the good news - I have it working on the surface. however my API key is publicly in the client side Javascript, and I need to figure out someway to hide it. This is currently what my code looks like: $.ajax({ type: 'post', url: 'https://domain

XSS(跨站脚本攻击)

戏子无情 提交于 2021-02-17 02:20:53
XSS(Cross-site scripting)跨站脚本攻击,是一种安全漏洞。 示例代码 1. XSS的含义 顾名思义,就是向web页面或者网站的url添加恶意的script(脚本)代码,使用户访问该网站时,执行恶意代码,从而达到攻击的目的。 发生XSS的场景: 1. 网站对用户的输入过滤不足,返回给用户的展示结果过滤不足。 2. 网站的链接地址未经过过滤 2. 如何进行攻击 攻击种类多种多样,通常包含如下: 1. 向网站注入脚本,获取访问用户的cookie或者其他会话信息(session information)等私有数据 2. 通过注入脚本,将受害者的网页重定向到攻击者控制的网页 3. 通过注入脚本,在用户的计算机上执行其他恶意操作 3. XSS攻击分类 XSS攻击分为3类: 存储型(持久型)、反射型(非持久型)、基于DOM型。危害程度递减。 存储型(Stored/Persistent XSS Attacks) 危害程度最大,可能危及所有用户! 注入的脚本永久的存储在目标服务器中。当浏览器发送数据请求时,受害者和网站的其他用户都会再次拿到恶意脚本。 <示例>: 网站的评论功能 评论提交后,存储到服务器。所有访问该网站的用户自动从服务器拉取到恶意代码。 // 在评论框中输入恶意脚本,提交到服务器 hello < script > 广告等 </ script > 反射型

Hide scrollbar (with scroll enabled)

拥有回忆 提交于 2021-02-17 02:18:52
问题 I have a table with 2 columns and multiple rows <table border=0 id="feed"> <tr><td>something</td><td><div class="bubble"></div></td></tr> <tr><td style="">something1</td><td><div class="bubble"></div></td></tr> <tr><td style="">something2</td><td><div class="bubble"></div></td></tr> <tr><td style="">something3</td><td><div class="bubble"></div></td></tr> <tr><td style="">something4</td><td><div class="bubble"></div></td></tr> <tr><td style="">something5</td><td><div class="bubble"></div></td>

filter only sublocalities in google maps api

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-17 02:15:14
问题 I want to get nearby sublocalities in google maps api var input = document.getElementById('searchTextField'); var autocomplete = new google.maps.places.Autocomplete(input, { types: ["geocode"] }); This adds autocomplete for all places being typed in the text box. I want to filter out only the sublocalities and get the nearby sub localities in the autocomplete Check the working version here 回答1: Types: ["(cities)"] will give you just localities. From the documentation : "types | Type: Array |

Flattening a nested object

帅比萌擦擦* 提交于 2021-02-17 02:00:50
问题 I have to convert JSON to the format below, I'm having a problem converting it back. Here is the current format [{ "id": "5", "parentid": "0", "text": "Device Guides", "index": 0, "children": [{ "id": "10", "text": "Grandstream GXP-21XX", "index": 0 }, { "id": "11", "text": "Polycom Soundstation/Soundpoint", "index": 1 }, { "id": "23", "text": "New Polycom", "index": 2 }] }, { "id": "6", "parentid": "0", "text": "Pre-Sales Evaluation", "index": 1, "children": [] }, { "id": "7", "parentid": "0

Click event doesn't fire on pages other than first

戏子无情 提交于 2021-02-17 01:58:52
问题 i am using the DataTable plugin to display data in my backend page. The plugin works so far very good except in one situation: I have a table showing all products. For each line of the table i have a link for AJAX activation / deactivation of one product. If i am on the first page the activation / deactivation works fine, but when i choose another page using the DataTable Pagination i cannot activate / deactivate the chosen product. It does not display any error in the Firebug, so i am