Domanda

I have a normal tag:

<a href="prefetchThisPage.html"> ... </a> 

I need it to look like this:

<a href="prefetchThisPage.html" data-prefetch> ... </a> 

Why? jQuery Mobile feature: http://jquerymobile.com/demos/1.1.1/docs/pages/page-cache.html

The expected way below does not add the attribute, probably because Tritium ignores empty attributes.

attribute("data-prefetch")

Any ideas?

È stato utile?

Soluzione

Great Question!

The best way to do this, is to set the value of the variable to the NAME of the variable.

I would do it like this:

$variable_name = "data-prefetch"
$("./a") {
  attribute($variable_name, $variable_name)
}

This is an HTML5 convention and should work for the purposes you illustrated!

Altri suggerimenti

Tritium currently has a short circuit that converts attribute assignments like the following declaration:

attribute("data-prefetch", "")

Into the equivalent of removing the attribute.

I strongly recommend you file this issue with Moovweb's help desk so that they add support for adding attributes with no values.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top